Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and Horizontal Scroll Bar

 
Michael Hildner
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Michael
 
eric moon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
HTH
e
 
Michael Hildner
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems to work OK:
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
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,
Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic