Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable problem

Status
Not open for further replies.

DPUser

Technical User
Oct 17, 2003
16
US
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top