[英]add rows to jTable
I'm doing an exercice about java swing, now it's time to add rows from a database to the jTable, I know that the method to do this is "addRow()" but netBeans doesn't suggest it to my and underline the line as a mistake. 我正在做一个关于java swing的练习,现在是时候将数据库中的行添加到jTable了,我知道执行此操作的方法是“addRow()”但netBeans不会向我建议并强调该行作为一个错误。
Is necesary to import something before, or does someone know what I'm doing bad? 是否需要先导入一些东西,或者有人知道我做得不好吗?
thanks. 谢谢。
addRow is an instance method of DefaultTableModel
rather than JTable
. addRow是DefaultTableModel
的实例方法,而不是JTable
。 Set the model for the JTable
and then add to it: 设置JTable
的模型,然后添加到它:
DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);
model.setColumnIdentifiers(new String[] { "Column 1", "Column 2"});
model.addRow(new String[] { "foo", "bar" });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.