This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 9990
    
    7

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
 
Similar Threads
repaint in ScrollPane does not work correctly
double to text
Problem with custom painting and multiple JPanel
Drawing with mouse
JScrollPane & JPanel dynamic changes