添加Component后JTable为空
我的 JTable 有问题,我试图放入每一行 JComboBoxes 和 JTextFields,但是当我加载应用程序时,我的表是空的。函数 getCmb* 和 getTxt* 返回 JComboBox 和 JTextField 并且工作正常,我检查过。
JTable tblCommands;
String[] columnTitles=new String[]{"Command","Offset","Type","Value","Units","Value Type","R/W"};
Object[][] data=new Object[20][7];
int row=0;
for(MessageCSVView message:messageContainer.getRows()){
data[row][0]=message.getCmbName();//this works
data[row][1]=message.getCmbOffset();//this works
data[row][2]=message.getTxtType();//this works
data[row][3]=message.getTxtValue();//this works
data[row][4]=message.getTxtUnit();//this works
data[row][5]=message.getTxtValueType();//this works
data[row][6]=message.getCmbRW();//this works
row++;
}
tblCommands=new JTable(data,columnTitles);
谁能告诉我我做错了什么?
I have problem with JTable, I am trying to put in each row JComboBoxes and JTextFields but when I load app, my table is empty. Functions getCmb* and getTxt* return JComboBox and JTextField and that works fine, I checked.
JTable tblCommands;
String[] columnTitles=new String[]{"Command","Offset","Type","Value","Units","Value Type","R/W"};
Object[][] data=new Object[20][7];
int row=0;
for(MessageCSVView message:messageContainer.getRows()){
data[row][0]=message.getCmbName();//this works
data[row][1]=message.getCmbOffset();//this works
data[row][2]=message.getTxtType();//this works
data[row][3]=message.getTxtValue();//this works
data[row][4]=message.getTxtUnit();//this works
data[row][5]=message.getTxtValueType();//this works
data[row][6]=message.getCmbRW();//this works
row++;
}
tblCommands=new JTable(data,columnTitles);
Can anybody tell me what I did wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您误解了
JTable
输入的方式。您需要创建
TableCellEditor
实现并将它们添加到表格的每一列。请参阅
JTable
上的 Swing 教程以获取更多信息。You misunderstand the way input works with
JTable
.You'll need to create
TableCellEditor
implementations and add them to each column of your table.Take a look at Swing tutorial on
JTable
for further information.示例片段
然后将其包含如下,
进一步阅读:
这是您最好的选择,JTable 的 Swing 教程。
Example Snippet
Then include it like below,
Further reading:
Here is your best bet, Swing tutorial for JTable.