• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Resizing a JScrollPane for a JTable

 
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Again, looking for advices…
I want to see a JTable in a JOptionPane. And I want to see the JScrollPane receiving the JTable without the scrollbars at first.
Here is the code:

The matter is the initial width is 828 pixels then one second later some column widths increase and the new total width is 894.

To correct this behavior, I just add the difference (66) in the formula to set the size of JScrollPane (lol)...
So is there a (simple) way to correct this?

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try overriding this method in JTable:If that works for you, and you don't understand why, please ask.
 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Darryl for your answer. In my case for a regular JTable
table.getPreferredScrollableViewportSize().toString() is java.awt.Dimension[width=450,height=400]

For a CTable where :

table.getPreferredScrollableViewportSize().toString() is java.awt.Dimension[width=440,height=400]

So, that does not work. Thank you anyway.
What I do not understand is why table.getColumnModel().getTotalColumnWidth() changes whereas the table has not been modified.
 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally, I got rid of doubles in the table and converted them to String using the Format class.
table.getColumnModel().getTotalColumnWidth() is ok now for what I need.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!