Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Horizontal Scroll Bar

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JScrollPane that I can't seem to slap a horizontal scroll bar onto.
Here's my code for my JScrollPane...

This scroll pane is sitting in a JPanel that has a layout of BorderLayout. Does that make a difference? When the table is populated with data, is sizes all of the columns so they fit within the panel. When the user expands one of the columns, I want them to be able to scroll horizontally. What am I doing wrong?
Thanks for any help!
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this on your table:
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked, however, now my columns are all scrunched together. How can I still have my scrollbar appear, but have the columns as wide as the column headings. Or, how can I specify what the column width is supposed to be for a particular column?
Thanks again!
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know for the scrollbar, but for the column's wide, you can proceed like this. I don't know if it is the best way.

I hope it's helping you
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Younes,
That worked! Now I have my horizontal scroll bar, and my columns aren't scrunched together!
Thanks for all of your help!
Have a GREAT day!!!
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx for the reply.
Nice to see it works
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic