aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Scrolling JPanel Squeezing All The UI Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scrolling JPanel Squeezing All The UI Components" Watch "Scrolling JPanel Squeezing All The UI Components" New topic
Author

Scrolling JPanel Squeezing All The UI Components

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Thanks Maneesh. That solved my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scrolling JPanel Squeezing All The UI Components