如何将数据插入JTable? [英] How to insert data into JTable?
本文介绍了如何将数据插入JTable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写此代码以在表格中显示字符串。
i write this code for showing strings in a table.
但它没有显示且无效。
什么是problrem?
what is problrem?
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。
I add Jtable on a panel.
在主要的添加面板中到一个jframe。
in the main add panel to a jframe.
JFrame frame = new JFrame();
frame.add(new pamnel());
frame.setVisible(true);
frame.setSize(600, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
显示表格但未显示数据。
表的行和列是空的!
The table is shown but data isn't show. the row and column of table is empty!
推荐答案
您必须将JTable添加到其父组件中setVisible()。
You have to add the JTable to its parent-component and setVisible().
这篇关于如何将数据插入JTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文