You could presumable achieve this by not setting AUTO_RESIZE_OFF until
the initial resizing has been allowed to occur. This won't fix the
problem though. Say you had two columns and instead of increasing the
columns widths the users choose to shrink them. You'll be back in
the situation where the table is narrower than the scroll pane and the
garbage will start appearing again.
I've also encountered this garbage and I get round it as follows:
- Define a JPanel with a GridBagLayout and have it implement Scrollable
- Add the table to the panel with the GridBagConstraints:
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
- Add a filler component to the panel:
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(new JComponent() {}, gbc);
- Delegate the Scrollable methods to the table
- Add the JPanel to the scroll pane instead of the JTable
- Because you're adding the JPanel to the scroll pane instead of the
JTable configureEnclosingScrollPane() will not get called on the
JTable. This basically means that you need to pass the table's
header to the scroll pane's setColumnHeaderView method yourself.
Regards
Dave Wathen
Goldman Sachs Asset Management
3rd Floor, Procession House
55 Ludgate Hill
London EC4M 7JN
+44 (0)20-7774-2998
It is not necessary to understand things in order to argue about them.
(Caron de Beaumarchais)
-----Original Message-----
From: Josef Bajada [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 22, 2001 2:54 AM
To: Advanced Swing
Subject: JTable
Hello,
I have a JTable in a JScrollPane whose number of columns and column
names are generated at runtime.
Since the number of columns may be large I opted to use the
AUTO_RESIZE_OFF setting so that the Horizontal Scrollbar can
appear and be used to scroll and view the different columns.
Now my problem is that sometimes the number of columns is small
(minimum is 2) and this will appear very un-neat for the table's
appearance since it will only take half the JScrollPane (apart from
that the unused area sometimes gets filled up with garbage when I
scroll vertically).
What I wish is that initially, all the columns are resized to fit the
width of the table, (identical to the way the AUTO_RESIZE_ALL_COLUMNS
works) but then the user can choose to expand the width of the columns
and then the Horizontal scrollbar appears.
How can I go about it?
Thanks,
Josef mailto:[EMAIL PROTECTED]
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing