Hi all, I have a jTable in netbeans, basically i have used the model feature to define the column headers and i create a set number of rows, say for this example 50. The problem i'm having is that this is pretty static and if i end up with more than 50 records i get an exception error. I could simple extented the rows but it seems a poor fix.
Is there a way to let the size of the jTable be changable, please remeber i'm using netbeans, so it's not so easy to edit the data directly.
Cheers
James
Steven Bell
Ranch Hand
Joined: Dec 29, 2004
Posts: 1071
posted
0
This must be something specific to the tools you are using. I don't think it is possible to set a static number of rows in a JTable (without creating your own table model).
What is the exception you are getting?
Jamie Wool
Ranch Hand
Joined: May 03, 2004
Posts: 49
posted
0
Getting an index out of bounds because the program is attempting to write to row 51 of a table with only 50 rows.
Steven Bell
Ranch Hand
Joined: Dec 29, 2004
Posts: 1071
posted
0
You must be using some custom table model, the DefaultTableModel uses a vector to store data, so you wouldn't get an IndexOutOfBounds error.
Could you post the stack trace, or at least the first 10-15 lines of it if it's really long.
That looks ok, as far as generated code goes. My guess is that where you are trying to add data it's calling the method DefaultTableModel.insertRow(int row, Object[] data); Where it should be calling DefaultTableModel.addRow(Object[] data);
If it was me I'd get away from the netbeans generated code and just hand write it.
P.S. when you post blocks of code like that you should sound it with code tags. Look for the code button under where you write your post. [ May 02, 2005: Message edited by: Steven Bell ]