我无法找到一种方法将数据插入JTable中的JPanel。 任何人都可以帮我搞清楚吗?我做错了什么?
这是我的代码:
JTabbedPane tabProcessamentoSalarial = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.addTab("Remunera\u00E7\u00F5es", null, tabProcessamentoSalarial, null);
JPanel pnlAcumulados = new JPanel();
tabProcessamentoSalarial.addTab("Acumulados", null, pnlAcumulados, null);
pnlAcumulados.setLayout(null);
table_1 = new JTable();
table_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
table_1.setBounds(46, 36, 508, 160);
pnlAcumulados.add(table_1);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(46, 36, 508, 160);
pnlAcumulados.add(scrollPane);
tblAcumulados = new JTable();
tblAcumulados.setBounds(46, 36, 508, 160);
tblAcumulados.setModel(new DefaultTableModel() {
String[] columnNamesRui = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
Object[][] dataRui = {
{"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe", "Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black", "Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White", "Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown", "Pool", new Integer(10), new Boolean(false)}
};
}
);
答案 0 :(得分:2)
我做错了什么?
为什么要从Swing教程中更改代码?教程代码工作正常,如果你不明白你在做什么,为什么还要对它进行修改?
使用How to Use Tables
上的Swing教程中的示例重新开始。