Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and its size

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I use a JTable with JScrollPane like this :

JScrollPane scrollPane = new JScrollPane(table);

where the table is my JTable but the resoult is a gigant table.For shrink it (make it smaller) I find two solution:
1.I set a preferred size for the frame and the table goes small
2.I set a prefferd size for the view port with : setPreferredScrollableViewportSize(..

The both solution require "hardcode" and I am not so happy with them.
My question is :
Thare are also other ways to resize the table without "hardcode" ?
 
Eric Snell
Greenhorn
Posts: 28
Java Mac MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a class that will calculate the PreferredScrollableViewportSize (along with some other things). Hope you find it helpful.


 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok it works,Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic