开发者

How to display a 2D array in jTable?

开发者 https://www.devze.com 2023-01-08 22:42 出处:网络
I have a static 2D array called Status.Data[][] and a Column header called Status.Columns[]. I am using net beans and I want to be able to have the arrays populate the table.

I have a static 2D array called Status.Data[][] and a Column header called Status.Columns[].

I am using net beans and I want to be able to have the arrays populate the table.

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        jTable1.setColumnModel(new DefaultColumnModel(Status.Data, Status.Columns));
    }

This throws an error that it is expecting a TableColumnModel.

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        jTable1.setColumnMo开发者_如何学JAVAdel(new TableColumnModel(Status.Data, Status.Columns));
    }

This says java.swing.table.TableColumnModel is abstract and cannot be instantiated.

I would even be happy if I could figure out how to make it display when the window is opened.

How do I populate my table?


You can create the table model and then pass it to the table constructor:

TableModel model = new DefaultTableModel(Status.Data, Status.Columns);
JTable table = new JTable(model);


use javax.swing.table.DefaultTableModel

DefaultTableModel(Object[][] data, Object[] columnNames)
0

精彩评论

暂无评论...
验证码 换一张
取 消