返回对象数组的方法
我似乎无法返回变量在这个方法数据
:
I just can't seem to return the variable data
in this method:
public Object[] populateTable(ArrayList<Outlet> outletList, String selection){
Object[] data;
for(int i = 0; i<outletList.size(); i++){
if(outletList.get(i).getCity().equalsIgnoreCase(selection)){
if(outletList.get(i).getStatus().equals("ACTIVE")){
String bar = outletList.get(i).getBarangay();
String code = Integer.toString(outletList.get(i).getCode());
String name = outletList.get(i).getName();
data = {bar, code, name};
}
}
}
return data;
}
NetBeans是说前pression的非法启动。有没有执行该法的方式进行,其中的数据(从传输到一个MySQL数据库来一个的ArrayList&LT;对象&gt;
在接口)传递给 [对象]
?寻找一种方法来填充数据从MySQL数据库来的JTable
行。
Netbeans is saying illegal start of expression. Is there a way to execute this method wherein data (coming from a mysql database transferred to a ArrayList<object>
in an interface) is passed to an Object[]
? Finding a way to populate JTable
rows with data coming from a mysql database.
错误就出现在这里:
data = {bar, code, name};
相反,构建对象
持有字符串
的实例的新数组:
data = new Object[]{bar, code, name};
然后就可以调用 addRow(数据)
在的DefaultTableModel
。一个完整的例子显示在 TableAddTest#addRow href=\"http://stackoverflow.com/a/19472190/230513\">()
。
Then you can invoke addRow(data)
on your DefaultTableModel
. A complete example is shown here in TableAddTest#addRow()
.