wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Need help with Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help with Layout" Watch "Need help with Layout" New topic

Need help with Layout

Paul Carter
Ranch Hand

Joined: Sep 20, 2006
Posts: 57
Still very new to Java and want to create a layout with 3 rows and 1 column, but with the rows of different and fixed heights.

setSize seems to have no effect on the contents, so I must be going about it the wrong way.

Can anyone give me an example of what I need to do?

Many thanks in advance.


public Tower(JFrame frame) {

super(new BorderLayout());
setLayout(new GridLayout(3, 1));

JLabel lCDLabel = new JLabel();

JFrame buttonsFrame = new JFrame("Buttons");
JPanel buttonsPanel = CreateTowerButtons();

buttonsPanel.setSize(new Dimension(100, 300));
lCDLabel.setSize(new Dimension(50, 50));


Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38033
Alternative: The place I learned to use GridBagLayout was not this classic Tutorial, entertaining though it may be. It was from Horstmann's book (C Horstmann, G Cornell, Core Java 2 (Volume I Fundamentals) (pages 430-440), Santa Clara CA, Sun Microsystems Press (Prentice-Hall) (2004)).
Read that chapter very carefully, and work out how the GBC class works, to speed setting the GridBagConstraints.

There is another version of the GBC class here.
Paul Carter
Ranch Hand

Joined: Sep 20, 2006
Posts: 57
Cheers guys - I'm up and running
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38033
Only too pleased to be able to help . . .
I agree. Here's the link: http://aspose.com/file-tools
subject: Need help with Layout
Similar Threads
Swing: Unable to bring down the size of JPanel
Java Board Game
Clip Board Problem
Need some basic swing help....
Need help