Reputation: 11201
I want to do a JTable with column names, using:
JTable(Vector rowData, Vector columnNames)
to constructs a JTable to display the values in the Vector of Vectors, rowData, with column names, columnNames.
So, I did this:
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);
But I only see the data, why isn't the title shown?
Thank in advance
Upvotes: 1
Views: 389
Reputation: 12538
JTable table = new JTable(columnData, columnNames);
JScrollPane scroll = new JScrollPane(table);
panel.add(scroll);
Upvotes: 4