• 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

Column sizing in JScrollPane

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
If any of you could help I would be grateful:
I have an application with a fixed window size, within this I have a JTabbedPane, each tab contains a JScrollPane which contains a JTable. The tables can have different numbers of columns. I am trying to achieve a uniform look and this is where I am having problems.
I set the columns to a minimum width. If there are few columns, less than the width of the JScrollPane, I would like the columns to resize to fill the scroll pane. This is acheivable by setting the auto resize mode to AUTO_RESIZE_ALL_COLUMNS.
If there are many columns I would like a horizontal scroll bar, this is achieved by setting the auto resize mode to AUTO_RESIZE_OFF, however to achieve both automatically is the problem.
You can achieve this effect by placing the table in a JPanel and adding the panel to the scroll pane but then you lose the column headings.
I would settle for being able to detect the size of the viewport, then I could calculate the minimum column size * the number of columns and set the resize mode accordingly. However when I get the viewport associated with the scroll pane I canot get its size (I used viewport.getExtentSize()), it always comes back with a width and height of 0.
Any ideas would be appreciated.
Regards,
Derek Drever
 
Derek Drever
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found a solution on another forum, just extend JTable and override the following method - works a treat.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic