Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Column sizing in JScrollPane

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Found a solution on another forum, just extend JTable and override the following method - works a treat.
 
    Bookmark Topic Watch Topic
  • New Topic