jtable标题未显示

时间:2012-05-07 07:50:18

标签: java jtable

我想用列名做一个JTable,使用:

JTable(Vector rowData, Vector columnNames)

构造一个JTable来显示Vector of Vector,rowData中的值,列名为columnNames。

所以,我这样做了:

final String[] columnNames = {"NOMBRE", "DÍAS DE LA SEMANA", "HORA DE INICIO", "HORA DE FIN", "TIEMPO MÁXIMO DE USO"};

        rs.last();
        int numRows = rs.getRow();
        rs.beforeFirst(); 

        Object[][] columnData = new String[numRows][5];

        int i = 0;
        while(rs.next()){

            columnData[i][0] = rs.getString(1);
            columnData[i][1] = rs.getString(2);
            columnData[i][2] = rs.getString(3);
            columnData[i][3] = rs.getString(4);
            columnData[i][4] = rs.getString(5);

        }

table = new JTable(columnData, columnNames);
        table.setBounds(300,600,700,150);

但我只看到数据,为什么不显示标题?

提前感谢

1 个答案:

答案 0 :(得分:4)

JTable table = new JTable(columnData, columnNames);
JScrollPane scroll = new JScrollPane(table);
panel.add(scroll);