我编写此代码用于在表中显示字符串。
但它没有显示并且没有任何效果。
有什么问题吗?
public pamnel() {
initComponents();
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"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)}
};
jTable1 = new JTable(data, columnNames);
}
编辑:
我在面板上添加 Jtable。
在主面板中将其添加到 jframe 中。
JFrame frame = new JFrame();
frame.add(new pamnel());
frame.setVisible(true);
frame.setSize(600, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
显示表格但未显示数据。
表格的行和列都是空的!