This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable and its size  RSS feed

 
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" ?
 
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!
 
Shiny ad:
free 1 hour java lesson
https://coderanch.com/t/695988/free-hour-java-lesson
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!