按钮放置

Button placement

我希望 money1 按钮位于 Jlabel 下方,表示 fillmeup 但是当我尝试添加按钮时,它位于 Label 的右侧,而不是在其下方。我正在使用小程序并使用 JButtons。任何建议将不胜感激。

这是GUI图片

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);

我会考虑参考这里的文档 Java Layout Options

并将 buttonPane2 布局管理器设置为满足您需要的布局管理器。

这可以使用 setLayout(new xxxLayout());