你好我在JScrollPane中显示我的JTable时出现问题。Java jTable在jScrollPane中不可见
这是我的代码:
table = new JTable();
table.setBounds(16, 203, 362, 16);
//getContentPane().add(table);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setModel(new DefaultTableModel(
new Object[][] {
{"2", "DN Korina", "200"},
},
new String[] {
"QTY", "Item Code", "Amount"
}
));
table.getColumnModel().getColumn(0).setPreferredWidth(105);
table.getColumnModel().getColumn(1).setPreferredWidth(244);
table.getColumnModel().getColumn(2).setPreferredWidth(220);
table.setBackground(Color.PINK);
JTableHeader header = table.getTableHeader();
header.setBackground(Color.yellow);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(16, 480, 359, -240);
getContentPane().add(scrollPane);
我使用windowbuilder亲,我无法看到JScrollPane的设计视图。如果我删除JScrollPane并让JTable单独运行,则JTable是可见的。但我看不到标题。我读过这个来查看JTable的头文件,JTable必须放在JScrollPane中。任何想法为什么我看不到我的JScrollPane和JTable?谢谢。
使用布局管理器,你的问题将消失 – Reimeus
@Reimeus我使用AbsoluteLayout。这有什么问题吗? – Dunkey
不要设置边界。一个布局_other_比AbsoluteLayout –