I am trying to create a JTable that gets its data from a ResultSet from a query. The JTable uses the DefaultTableModel as in:
private String[] colHeads ={"Name","City","Street"};
private DefaultTableModel model = new DefaultTableModel(colHeads,0);
private JTable table = new JTable(model);
private JScrollPane scrollPane = new JScrollPane(table);
------------------
Then I go on to set the row and columns as in:
model.setRowCount(5);
model.setColumnCount(5);
-------------
I can now loop through the ResultSet and add the rows as in:
while (rsData.next() ){
Object[] cells={rsData.getString(1),rsData.getString(2),rsData.getString(3),rsData.getString(4)};
model.addRow(cells);
-------------------------
The problem that I am having is that I would think that setRowCount(5) and setColumnCount(5) would mean that there is going to be a JTable on screen containing 5 rows and 5 columns with scrollbars to allow the user to see the other rows and columns. This is not the case, what happens is the JTable has 5 blank rows before the rows that contain data. The columns are set to 5. There is no scrollbars. PLEASE HELP.
Thank you
private String[] colHeads ={"Name","City","Street"};
private DefaultTableModel model = new DefaultTableModel(colHeads,0);
private JTable table = new JTable(model);
private JScrollPane scrollPane = new JScrollPane(table);
------------------
Then I go on to set the row and columns as in:
model.setRowCount(5);
model.setColumnCount(5);
-------------
I can now loop through the ResultSet and add the rows as in:
while (rsData.next() ){
Object[] cells={rsData.getString(1),rsData.getString(2),rsData.getString(3),rsData.getString(4)};
model.addRow(cells);
-------------------------
The problem that I am having is that I would think that setRowCount(5) and setColumnCount(5) would mean that there is going to be a JTable on screen containing 5 rows and 5 columns with scrollbars to allow the user to see the other rows and columns. This is not the case, what happens is the JTable has 5 blank rows before the rows that contain data. The columns are set to 5. There is no scrollbars. PLEASE HELP.
Thank you