• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with Layout

 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers guys - I'm up and running
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only too pleased to be able to help . . .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic