File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable Problem - Urgent !!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Problem - Urgent !!!!" Watch "JTable Problem - Urgent !!!!" New topic

JTable Problem - Urgent !!!!

Seema Hanji
Ranch Hand

Joined: Jan 29, 2001
Posts: 37
I have a JTable inside a JScrollPane which is added to a JPanel and this panel is added to a JTabbedPane. tabbedPane is added to a JPanel.
I dynamically populate JTable from a sql query and which has a large number of columns (around 30-40).
The problem is all columns are not visible in the JTable, though I scroll horizontal scrollBar to right. I tried to change the size of tabbedPane and panel... still didn't work.
Anybody know solution for this.
Appreciate if you could reply soon.
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
check out ur may be to do with the size of the Scrollpane.Also,in scrollpane ,u got a constructor which specifies scrollbar policy.
JScrollPane(int vsbPolicy, int hsbPolicy)
try it out..
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Seema,
Let me see if I got this straight. Initially your table has small number of columns, if any, and then you populate it and it gets 30-40 columns of data.
I would think that the ScrollPane probably doesn't revalidate after all the columns are added (assuming of course that your panels are sizing correctly). You might try and call revalidate on the ScrollPane after do something on your table that changes it size (less rows or more/less columns). The ScrollPane uses its size versus the preferredSize of its' child to calculate the size of its scrollBar.
Seema Hanji
Ranch Hand

Joined: Jan 29, 2001
Posts: 37
Thanks for all of your responses.
I solved this problem. I was setting column widths using TableColumn.setMinWidth(). I replaced this with TableColumn.setPreferredWidth() and all columns are visible now.
I agree. Here's the link:
subject: JTable Problem - Urgent !!!!
jQuery in Action, 3rd edition