• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JTable static size problems

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the code that netbeans generates

salesBrowseResultsTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{new Integer(12), "Rose", "el rosia", "Goodhew", new Integer(56), new Float(6.99), "spato", "red", "Summer", new Integer(56), new Integer(12)},
{new Integer(16), "Tree", "el tree", "oak", new Integer(1), new Float(100.0), "treeus", "green", "summer", new Integer(1000), null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
},
new String [] {
"Shrub Id", "Shrub Name", "Latin Name", "Variety", "In Stock", "Price", "Genus", "Colour", "Flowering", "Height", "Width"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Float.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class
};
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic