This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 37940
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: 37940
Only too pleased to be able to help . . .
I agree. Here's the link:
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