This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help with Layout" Watch "Need help with Layout" New topic
Author

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.

Paul.


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.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

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

setBackground(Color.black);
add(lCDLabel);
add(picLabel);
add(buttonsPanel);

tc.SetUpGame();
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Only too pleased to be able to help . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with Layout