Discussion:
Set Preferred Width of JTable column using NetBeans
Kenneth George
2007-01-23 00:21:40 UTC
Permalink
I have an issue where the headers/columns in a JTable are wider than what is
displayed. Every example that I have found to correct this explains that I
need to make my own TableCell Renderer or my own JTable. How do I do
something like this for an application that was developed using Matisse?
Tomas Pavek
2007-01-23 15:45:50 UTC
Permalink
Post by Kenneth George
I have an issue where the headers/columns in a JTable are wider than
what is displayed. Every example that I have found to correct this
explains that I need to make my own TableCell Renderer or my own
JTable. How do I do something like this for an application that was
developed using Matisse?
Just like you would do for hand-written app. Of course you can't write the
code to the guarded area, but you can set anything you need on the table e.g.
in the constructor of the form class (after initComponents() call). In case of
providing own JTable subclass, the easiest way is to write it as an innerclass
and then in GUI builder select the original JTable, go to the properties ->
Code -> Custom Creation Code and write code for creating your specific table
class (new MySpecialTable(); ).

BTW I don't quite understand the problem you're trying to solve. The columns
are wider than the JTable, so a scrolbar appears?

- Tomas
Kenneth George
2007-01-23 16:39:27 UTC
Permalink
Thanks for responding. The problem is that I have a dataset that is 11000
rows by 152 columns. All the columns are their default values (really,
really, small) and I want them to be re-sized to the appropriate preferred
width based on either the header name, or the column data, whichever is
bigger.

Now, I did purchase a book last night after writing the email (Swing Hacks
by O'REILLY) that mentions a solution to this. However, since I have such a
large dataset (this is sample data, the real data will probably be much,
much larger), the time it takes to set the columns is huge (almost 30-45 sec
to reformat the table). This is due to the fact that ALL rows/cols of data
is looked at to get the correct column size.

Do you know a more proficient way of doing this?
Post by Tomas Pavek
Post by Kenneth George
I have an issue where the headers/columns in a JTable are wider than
what is displayed. Every example that I have found to correct this
explains that I need to make my own TableCell Renderer or my own
JTable. How do I do something like this for an application that was
developed using Matisse?
Just like you would do for hand-written app. Of course you can't write the
code to the guarded area, but you can set anything you need on the table e.g.
in the constructor of the form class (after initComponents() call). In case of
providing own JTable subclass, the easiest way is to write it as an innerclass
and then in GUI builder select the original JTable, go to the properties ->
Code -> Custom Creation Code and write code for creating your specific table
class (new MySpecialTable(); ).
BTW I don't quite understand the problem you're trying to solve. The columns
are wider than the JTable, so a scrolbar appears?
- Tomas
Loading...