Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Resizing a JScrollPane for a JTable  RSS feed

 
Greg Pata
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?

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • 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!