【发布时间】:2020-07-02 07:54:12
【问题描述】:
我在JScrollPane 中创建了一个JTable,但它没有显示在程序中。
这是我的代码:
scrollPaneTable = new JScrollPane();
scrollPaneTable.setBounds(10, 507, 854, -480);
table = new JTable();
table.setForeground(Color.BLACK);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setCellSelectionEnabled(true);
table.setFillsViewportHeight(true);
table.setBackground(Color.LIGHT_GRAY);
table.setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.GRAY, null));
table.setModel(new DefaultTableModel(
new Object[][] {
{"PC", "Computer", "Dominik", "Test", "Test"},
},
new String[] {
"Name", "Beschreibung", "Nutzer", "Ort", "Seriennummer"
}
));
table.setColumnSelectionAllowed(true);
table.setVisible(true);
scrollPaneTable.setViewportView(table);
jFW.getContentPane().add(scrollPaneTable);
【问题讨论】:
-
当然你的 JTable 没有出现。没有 main 方法,也没有定义 JFrame。您的代码甚至无法编译。
-
这里是完整代码:hastebin.com/aqafafuray.java
-
1) “这里是完整代码:” 不要在外部站点发布代码链接。为了尽快获得更好的帮助,edit 添加minimal reproducible example 或Short, Self Contained, Correct Example。 2) Java GUI 必须在不同的语言环境中使用不同的 PLAF 在不同的操作系统、屏幕尺寸、屏幕分辨率等上工作。因此,它们不利于像素完美布局。而是使用布局管理器,或 combinations of them 以及 white space 的布局填充和边框。