例如,我有一个数组[1 2 1 1 1 1 ]
。现在我想在表的不同单元格中设置它
如代码所示,我想将[1 2 1 1 1 1]
放在此表中。
class datatablenew extends JFrame {
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
public datatablenew() {
setTitle("dynamic data");
setSize(300, 200);
setBackground(Color.gray);
// Create a panel to hold all other components
JPanel datapanel = new JPanel();
datapanel.setLayout(new BorderLayout());
getContentPane().add(datapanel);
// Create columns names
String rowData[]={"row 1","row 2","row 3"};
String columnname[]={"column 1","column 2","column3"};
// Create some data
String dataValues[][] =
{
{ "", "", "" },
{ "", "", "" },
{ "", "", "" },
{ "", "", "" }
};
// Create a new table instance
table =new JTable(dataValues,columnname);
table=new JTable(dataValues,rowData);
Add the table to a scrolling pane
scrollPane=new JScrollPane(table);
datapanel.add(scrollPane,BorderLayout.CENTER);
}
}