回答編集履歴

2

追記

2018/07/31 23:04

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -8,19 +8,13 @@
8
8
 
9
9
 
10
10
 
11
- **コンパイル通してません**が、こんな感じのメソッドを`test`クラス側に
12
-
13
-
14
-
15
11
  ```Java
16
12
 
17
13
  import java.io.File;
18
14
 
15
+ import java.net.URL;
16
+
19
17
  import java.util.Objects;
20
-
21
-
22
-
23
- import java.util.Optional;
24
18
 
25
19
 
26
20
 
@@ -60,15 +54,37 @@
60
54
 
61
55
  import java.nio.file.Paths;
62
56
 
57
+
58
+
59
+ public class MyComponent extends JLayeredPane {
60
+
61
+ ImageIcon icon1 = new ImageIcon(Paths.get(test.EXECUTABLE_PATH.toString(), "背景画像.png").toFile().toString());
62
+
63
+ JLabel label1 = new JLabel(icon1); // 背景のラベル
64
+
65
+ MyComponent() {
66
+
67
+ // ※コンポーネントのサイズが指定されていません。
68
+
63
- import java.nio.file.Path;
69
+ label1.setSize(50, 50);
70
+
71
+ add(label1); // コンテナに背景を加える
72
+
73
+ System.out.println(Paths.get(test.EXECUTABLE_PATH.toString(), "背景画像.png").toFile().toString());
74
+
75
+ System.out.println(test.EXECUTABLE_PATH.toString());
76
+
77
+ }
78
+
79
+ }
64
80
 
65
81
 
66
82
 
67
- //
83
+ ```
68
84
 
69
- ImageIcon icon1 = new ImageIcon(Paths.get(test.EXECUTABLE_PATH.toString(), "背景画像.png").toURI().toURL());
85
+ Swingの画面レイアウトをデバックするときは画面をクリックしてCtrl+Shift+F1を押下すると、
70
86
 
71
- ```
87
+ コンソールにSwingのコンポーネントツリーが出力されます。
72
88
 
73
89
 
74
90
 

1

追記

2018/07/31 23:04

投稿

umyu
umyu

スコア5846

test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- **コンパイル通してません**が、こんな感じのメソッドをtestクラス側に
11
+ **コンパイル通してません**が、こんな感じのメソッドを`test`クラス側に
12
12
 
13
13
 
14
14
 
@@ -34,7 +34,7 @@
34
34
 
35
35
  try {
36
36
 
37
- URL location = test .class.getProtectionDomain().getCodeSource().getLocation();
37
+ URL location = test.class.getProtectionDomain().getCodeSource().getLocation();
38
38
 
39
39
  f = new File(location.toURI().getPath());
40
40
 
@@ -52,7 +52,9 @@
52
52
 
53
53
  ```
54
54
 
55
+
56
+
55
- MyComponent クラス側は
57
+ `MyComponent`クラス側は
56
58
 
57
59
  ```Java
58
60
 
@@ -67,3 +69,9 @@
67
69
  ImageIcon icon1 = new ImageIcon(Paths.get(test.EXECUTABLE_PATH.toString(), "背景画像.png").toURI().toURL());
68
70
 
69
71
  ```
72
+
73
+
74
+
75
+ あとクラス名は`test`とかではなく、実態にそうクラス名にしてくださいな。
76
+
77
+ 例えば、`test`ではなく`MainApplication`など。