File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scrolling JPanel Squeezing All The UI Components

 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've a JPanel added to a JScrollPane.
In the JPanel, I added a lot of JLabel/JTextField
on purpose to make sure that scrollbars appear.

The scrollbars came out but I ended up with
cramped JLabel/JTextField instead.

This is a link to how it looks like:
http://www.imagebam.com/image/b69f6375343718


Below is my code:



Could anyone please advise what's wrong with my code.

Thanks.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get rid of getMinimumSize and getPreferredSize. You don't need that.
GridLayout, like many other layouts has a facility where you can control the gap/space between components. Check out GridLayout#setHgap and setVgap methods. You will also find a corresponding constructor.

As a rule of the thumb try and avoid explicitly tweaking the dimensions of the child component. Always try and tweak the layout.
 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh. That solved my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic