• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

scrollbar problem resizing jtable in gridbag

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've got a table with a jscrollpane in a gridbag layout. I've set the gridbag constraints for the table to:
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
so that when the frame is resized the table expands. This all works fine.
The problem arises when the frame is expanded to a width greater than the table. When this happens the vertical scrollbar detached itself from the side of the table and keeps attached to the right hand edge of the frame. This leaves a grey gap between the right hand edge of the table and the vertical scrollbar.
Does anyone have any ideas how I might keep the scollbar attached permanently to the right hand edge of the table, no matter how wide the frame becomes.
Thanks
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nigel,
What's happening is that the table is expanding but the sum of the cell widths is not. This gives you a gap between the cells and the table edge. The default background for the area beneath the cells is gray.
One possible solution could be to set up a large maxWidth for the cells so the sum of them will never be exceeded by the table background.
Hope that helps,
Terry
 
Nigel Patching
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advice Terry. That would certainly work if I had enough cells and they are wide enough (as you said).
However, I am curious to know whether there is another solution to this problem which allows me to keep the cell widths relatively narrow.
Nigel
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try seting the scrollable part of the table dynamically as content is added ( or fixed at the start if you prefer)
use:
table.setPreferredScrollableViewportSize( Dimension d )
Hope that does the trick,
Terry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic