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 and Horizontal Scroll Bar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and Horizontal Scroll Bar" Watch "JTable and Horizontal Scroll Bar" New topic

JTable and Horizontal Scroll Bar

Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
I have a JTable with many columns, so many that the column headers are too small. I'm trying to figure out how to set a minimum size for the headers and have the user scroll horizontally to see all the fields.
I have the table in a JScrollPane, wrote some code to set minimum column size, but it doesn't seem to work - vertical scroll bar shows up when it should, but not the horizontal scroll bar, so column headers are still small.
I've looked around, but couldn't find code to scroll the table horizontally. Any ideas?
Thanks in advance,
eric moon
Ranch Hand

Joined: Nov 26, 2000
Posts: 133
I've always had to set minimum, maximum and preferred size to convince Swing not to squeeze everything in, even in a scrollPane.
Does that work for you? If you figure out which ones you really have to set, let me know! But setting minimum doesn't seem to do it.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>"Those who cast the votes decide nothing. Those who count the<BR>votes decide<BR>everything." <BR> -Joseph Stalin<HR></BLOCKQUOTE>
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
This seems to work OK:
All headers are the same size. It's a little wierd because the colums don't expand to fill the entire scroll pane area if there are just a couple columns, but for tables with many columns, a horizontal scroll bar shows up.
I'm going to play around and see if I can't write some code that sizes individual colums to be just big enough to fit the column name.
Thanks for the info,
I agree. Here's the link:
subject: JTable and Horizontal Scroll Bar
It's not a secret anymore!