我有一个使用swing 接口的主类。我可以显示一个 JScrollPane。我有一个填充表格的动作侦听器,应该将表格添加到 JScrollPane。但是,当我初始化 scrollPane 时,我需要将(表示例)声明为参数...无法弄清楚在填充后如何引用它。继承人的代码:
JScrollPane callsScroll = new JScrollPane();
JPanel callsArea = new JPanel();
....
callsArea.add(callsScroll);
callsScroll.setPreferredSize(new Dimension(570, 400));
...
while (rs.next()) {
String columns[] = {"Employee ID", "Date", "Billing Type", "DR", "Call Time", "Trouble Code", "Invoice Amount", "Invoice Number"};
Object data[][]={
{rs.getString("EmployeeID"),rs.getString("Date"),rs.getString("BillingType"),
rs.getString("DR"),rs.getString("CallTime"),rs.getString("TroubleCode"),
rs.getString("InvoiceAmount"),rs.getString("InvoiceNumber")
},
};
JTable table = new JTable(data,columns);
gui.callsScroll.add(table);
gui.callsArea.add(gui.callsScroll);
}
我知道表格正在被填充,因为我可以将它直接添加到 JFrame。但我不能先把它放到桌子上。我需要能够在此处填充表后引用该表的实例 JScrollPane callsScroll = new JScrollPane(right here);
** * ** *编辑* ** * ** * ** * ** * *
Object[][] data=null;
while (rs.next()) {
data[][]={
{rs.getString("EmployeeID"),rs.getString("Date"),rs.getString("BillingType"),
rs.getString("DR"),rs.getString("CallTime"),rs.getString("TroubleCode"),
rs.getString("InvoiceAmount"),rs.getString("InvoiceNumber")},
};
}