回答編集履歴
2
最初の質問内容についての回答を追記
answer
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
GlassPaneとLayeredPaneが抜けている事以外では質問文の画像で構成はあってます。
|
2
|
+
参考になりそうな資料としては
|
3
|
+
[Using Top-Level Containers (英語)](https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html)
|
4
|
+
[How to Use Root Panes (英語)](https://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html)
|
5
|
+
[JRootPane (日本語)](https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JRootPane.html)
|
6
|
+
この3つでしょうか。
|
7
|
+
|
1
8
|
Swingの画面をクリックして**ctrl+Shift+F1**を押下すると、コンソールにSwingのコンポーネント階層が出力されます。
|
2
9
|
質問者さんのソースコードだと以下のコンポーネント階層になります。。
|
3
10
|
```Java
|
1
変数名:panelをmainPanelに変更
answer
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
質問文のソースコードではcontainer内にJPanelを複数枚追加しています。
|
18
18
|
ボタンの周りの表示はJPanelが表示されているために発生する現象です。
|
19
19
|
|
20
|
-
JPanelを一つに変更し
|
20
|
+
JPanelを一つに変更しJPanelに画像(JLabel)とボタン2個を設置したソースコードです。ご参考まで。
|
21
21
|
```Java
|
22
22
|
import java.io.File;
|
23
23
|
import java.net.URL;
|
@@ -68,26 +68,24 @@
|
|
68
68
|
setContentPane(contentPane);
|
69
69
|
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
|
70
70
|
|
71
|
-
JPanel
|
71
|
+
JPanel mainPanel = new JPanel();
|
72
|
-
contentPane.add(
|
72
|
+
contentPane.add(mainPanel);
|
73
|
-
|
73
|
+
mainPanel.setLayout(null);
|
74
74
|
|
75
75
|
JButton newButton = new JButton("最初から");
|
76
76
|
newButton.setBounds(162, 248, 101, 25);
|
77
|
-
|
77
|
+
mainPanel.add(newButton);
|
78
78
|
|
79
79
|
JButton continueButton = new JButton("続きから");
|
80
80
|
continueButton.setBounds(162, 319, 101, 25);
|
81
|
-
|
81
|
+
mainPanel.add(continueButton);
|
82
82
|
|
83
|
-
JLabel
|
83
|
+
JLabel labelBackGround = new JLabel("");
|
84
|
-
|
84
|
+
labelBackGround.setBounds(0, 0, 517, 471);
|
85
|
-
|
85
|
+
labelBackGround.setIcon(new ImageIcon(Paths.get(EXECUTABLE_PATH.toString(), "bg.png").toString()));
|
86
|
-
|
86
|
+
mainPanel.add(labelBackGround);
|
87
87
|
}
|
88
88
|
}
|
89
|
-
|
90
89
|
```
|
91
|
-
|
92
90
|
■余談
|
93
91
|
Swingで画面レイアウトを作成する時は、eclipseのプラグインのWindowBuilderを使うと画面レイアウトの作成負荷が軽減されます。
|