toningbasher
toningbasher

Reputation: 3

Button placement

I want money1 button to be below the Jlabel saying fillmeup but when I do try to add a button it goes to the right of Label not under it. I am using an applet and using JButtons. Any advice would be much appreciated.

Here is the GUI picture enter image description here

The blackJack game I am trying to make

    setBackground( new Color(130,50,40) );
    setLayout( new BorderLayout(3,3) );

    BlackjackCanvas board = new BlackjackCanvas();
    add(board, BorderLayout.CENTER);      

    Panel buttonPanel = new Panel();
    buttonPanel.setBackground(new Color(220,200,180));
    add(buttonPanel, BorderLayout.SOUTH);

    Panel buttonPane2 = new Panel();
    buttonPane2.setBackground(new Color(220,200,180));
    add(buttonPane2, BorderLayout.EAST);

    Panel buttonPane3 = new Panel();
    buttonPane3.setBackground(new Color(220,200,180));
    add(buttonPane3, BorderLayout.WEST);

    Button hit = new Button( "Hit!" );
    hit.addActionListener(board);
    hit.setBackground(Color.lightGray);
    buttonPanel.add(hit);

    Button stand = new Button( "Stand!" );
    stand.addActionListener(board);
    stand.setBackground(Color.lightGray);
    buttonPanel.add(stand);

    Button newGame = new Button( "New Game" );
    newGame.addActionListener(board);
    newGame.setBackground(Color.lightGray);
    buttonPanel.add(newGame);

    JLabel money = new JLabel( "Fill me up!" );
    money.setBackground(Color.lightGray);
    buttonPane2.add(money);

    Button money1 = new Button( "A rare commodity" );
    newGame.addActionListener(board);
    newGame.setBackground(Color.lightGray);
    buttonPane2.add(money1);

Upvotes: 0

Views: 45

Answers (1)

Steven Kirby
Steven Kirby

Reputation: 26

I would consider referring to the docs here Java Layout Options

And setting buttonPane2 layout manager to the one that meets your needs.

This can be done using setLayout(new xxxLayout());

Upvotes: 1

Related Questions