Ben
Ben

Reputation: 1142

JTable vs. custom TableModel

I am trying to implement a JTable on a Java GUI that can fill itself with values from a file and allow the user to make modifications to various cells. Since I'm using the GUI editor in the Netbeans IDE, my first instinct was to add the JTable to my form from the palette. however, I quickly realized that I couldn't add more than 100 rows to the table (for my application i'd need around 500+). additionally, while searching for a solution to this problem, I noticed a lot of people saying to use a Custom TableModel instead of using the JTable because it is more robust/efficient.

first, is there a way to add more than 100 rows to a JTable? secondly, is using the JTable (which uses the DefaultTableModel) really a bad implementation? my form is pretty complex, so I would prefer to use the GUI editor to adjust the size, position, etc. of my JTable as opposed to hard-coding it.

Upvotes: 3

Views: 2229

Answers (3)

Saleem
Saleem

Reputation: 21

Very Simple to increase rows manually rather than to increase them through GUI :

  1. Right Click on your newly designed jTable
  2. Select Customize Code
  3. Change the DEFAULT CODE to CUSTOMER PROPERTY (where the object creation started for rows)
  4. By Default null rows are 100
  5. COPY and PASTE the the NULL rows as maximum you need
  6. CLICK ok. Now your table rows size INCREASED as needed

Upvotes: 2

camickr
camickr

Reputation: 324118

is there a way to add more than 100 rows to a JTable?

Why is 100 a limit? That sounds like your IDE, not the DefaultTableModel. Tens of thousands of rows is no problem for the DefaultTableModel (not that any user would want to look at all that data).

Upvotes: 3

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

Most Swing GUI coders that I know don't "hard-code" their GUI's but rather use the easier to use layout managers (BorderLayout, GridLayout, BoxLayout, FlowLayout, MigLayout, FormLayout, etc...) to do the heavy lifting for them and to allow their complex GUI's to be resizeable and decent looking on multiple platforms. Regarding your other issue, it's not whether to use a JTable or a custom model since if you're using a JTable, you'll be using a JTable whether or not the model is default or custom, but if you're doing anything complex, then yeah, you'll likely want to add your own TableModel to your JTable. They're not that hard to create, and w can help you with it. I do wonder about your 500 line requirement -- there's no way that anyone will need or want to look at 500 lines at one time. Perhaps you want to use a database and load and remove rows into your TableModel as needed.

Upvotes: 2

Related Questions