1

どうすればその灰色のボックスを取り除くことができますか?

これは私が話していることです:

あなたが私を助けることができれば、私は本当に感謝します

完全なコードはこちら: http://pastebin.com/nrpCTjvV

public final void initUI() {

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    panel.setBorder(new EmptyBorder(new Insets(90, 155, 40, 60)));

    JButton NewGame = new JButton  ("New Game!");
    JButton Highscore = new JButton("Highscore");
    JButton Credits = new JButton  ("Credits");
    JButton Website = new JButton  ("Website");
    JButton Exit = new JButton     ("Exit");

    panel.add(NewGame);
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(Highscore);
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(Credits);
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(Website);
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(Exit);

    final ButtonGroup entreeGroup = new ButtonGroup();
    JRadioButton radioButton;
    panel.add(radioButton = new JRadioButton("Music1"));
    radioButton.setActionCommand("Music1");
    entreeGroup.add(radioButton);
    panel.add(radioButton = new JRadioButton("Music2"));
    radioButton.setActionCommand("Music2");
    entreeGroup.add(radioButton);
    panel.add(radioButton = new JRadioButton("No Music", true));
    radioButton.setActionCommand("No Music");
    entreeGroup.add(radioButton);

    add(panel);
    pack();

    setTitle("Title");
    JLabel background = new JLabel(new ImageIcon("background.png"));
add(background);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setResizable(false);
    setSize(400, 400);

}
4

1 に答える 1

3
add(panel);
pack();
setTitle("Title");
JLabel background = new JLabel(new ImageIcon("background.png"));
add(background);

JFrame のデフォルトのレイアウト マネージャーは BorderLayout です。制約を指定せずにコンポーネントを追加すると、コンポーネントは CENTER に追加されます。複数のコンポーネントを 1 つの場所に追加することはできません。

代わりに、別のコンポーネントを背景として使用する必要があります。次に、パネルをこのコンポーネントに追加します。背景パネルをご覧ください。次に、コードは次のようになります。

Background background = new BackgroundPanel(...);
background.add(panel);
add(background);
setResizable(false);
pack();
...
于 2013-04-16T16:43:51.120 に答える