回答編集履歴

2

最初の質問内容についての回答を追記

2018/01/17 15:41

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -1,3 +1,17 @@
1
+ GlassPaneとLayeredPaneが抜けている事以外では質問文の画像で構成はあってます。
2
+
3
+ 参考になりそうな資料としては
4
+
5
+ [Using Top-Level Containers (英語)](https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html)
6
+
7
+ [How to Use Root Panes (英語)](https://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html)
8
+
9
+ [JRootPane (日本語)](https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JRootPane.html)
10
+
11
+ この3つでしょうか。
12
+
13
+
14
+
1
15
  Swingの画面をクリックして**ctrl+Shift+F1**を押下すると、コンソールにSwingのコンポーネント階層が出力されます。
2
16
 
3
17
  質問者さんのソースコードだと以下のコンポーネント階層になります。。

1

変数名:panelをmainPanelに変更

2018/01/17 15:41

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
 
38
38
 
39
- JPanelを一つに変更して、JPanelに画像とボタン2個を設置したソースコードです。ご参考まで。
39
+ JPanelを一つに変更しJPanelに画像(JLabel)とボタン2個を設置したソースコードです。ご参考まで。
40
40
 
41
41
  ```Java
42
42
 
@@ -138,11 +138,11 @@
138
138
 
139
139
 
140
140
 
141
- JPanel panel = new JPanel();
141
+ JPanel mainPanel = new JPanel();
142
142
 
143
- contentPane.add(panel);
143
+ contentPane.add(mainPanel);
144
144
 
145
- panel.setLayout(null);
145
+ mainPanel.setLayout(null);
146
146
 
147
147
 
148
148
 
@@ -150,7 +150,7 @@
150
150
 
151
151
  newButton.setBounds(162, 248, 101, 25);
152
152
 
153
- panel.add(newButton);
153
+ mainPanel.add(newButton);
154
154
 
155
155
 
156
156
 
@@ -158,27 +158,23 @@
158
158
 
159
159
  continueButton.setBounds(162, 319, 101, 25);
160
160
 
161
- panel.add(continueButton);
161
+ mainPanel.add(continueButton);
162
162
 
163
163
 
164
164
 
165
- JLabel lblNewLabel = new JLabel("");
165
+ JLabel labelBackGround = new JLabel("");
166
166
 
167
- lblNewLabel.setBounds(0, 0, 517, 471);
167
+ labelBackGround.setBounds(0, 0, 517, 471);
168
168
 
169
- lblNewLabel.setIcon(new ImageIcon(Paths.get(EXECUTABLE_PATH.toString(), "bg.png").toString()));
169
+ labelBackGround.setIcon(new ImageIcon(Paths.get(EXECUTABLE_PATH.toString(), "bg.png").toString()));
170
170
 
171
- panel.add(lblNewLabel);
171
+ mainPanel.add(labelBackGround);
172
172
 
173
173
  }
174
174
 
175
175
  }
176
176
 
177
-
178
-
179
177
  ```
180
-
181
-
182
178
 
183
179
  ■余談
184
180