質問編集履歴
3
画像の追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
コードを<code>ボタンで挿入。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,220 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
import java.awt.Font;
|
4
|
+
|
5
|
+
import java.awt.event.ActionEvent;
|
6
|
+
|
7
|
+
import java.awt.event.ActionListener;
|
8
|
+
|
9
|
+
import java.io.File;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
import javax.swing.JButton;
|
14
|
+
|
15
|
+
import javax.swing.JFrame;
|
16
|
+
|
17
|
+
import javax.swing.JList;
|
18
|
+
|
19
|
+
import javax.swing.JScrollPane;
|
20
|
+
|
21
|
+
import javax.swing.event.ListSelectionEvent;
|
22
|
+
|
23
|
+
import javax.swing.event.ListSelectionListener;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
public class TEST1 extends JFrame implements ListSelectionListener {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
static String[] file_name;
|
32
|
+
|
33
|
+
String[] file_name2 = new String[200];
|
34
|
+
|
35
|
+
String[] folder = new String[200];
|
36
|
+
|
37
|
+
String[] name = new String[200];
|
38
|
+
|
39
|
+
static String url1;
|
40
|
+
|
41
|
+
String url2;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
public TEST1() {
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
url1 = "C:\Users\表示テスト\";
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
setSize(1300, 750);
|
56
|
+
|
57
|
+
setLayout(null);
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
button1();
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
list_sakusei();
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//空のリストボックス作成
|
76
|
+
|
77
|
+
public void list_sakusei() {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
JList lst0 = new JList(file_name2);
|
82
|
+
|
83
|
+
lst0.addListSelectionListener(this);
|
84
|
+
|
85
|
+
JScrollPane lst1 = new JScrollPane(lst0);
|
86
|
+
|
87
|
+
lst1.setBounds(240, 150, 470,400);
|
88
|
+
|
89
|
+
getContentPane().add(lst1);
|
90
|
+
|
91
|
+
setVisible(true);
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
public void button1() {
|
102
|
+
|
103
|
+
JButton button1 = new JButton("ボタン1");
|
104
|
+
|
105
|
+
button1.setFont(new Font("Gothic", Font.PLAIN, 13));
|
106
|
+
|
107
|
+
button1.setBounds(80,150,150,30);
|
108
|
+
|
109
|
+
add(button1);
|
110
|
+
|
111
|
+
button1.addActionListener(new button1());
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
public void valueChanged(ListSelectionEvent e) {
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
JList lst1 = (JList)e.getSource();
|
124
|
+
|
125
|
+
url2 = url1+lst1.getSelectedValue();
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
//aフォルダの一覧を抽出する
|
130
|
+
|
131
|
+
File file2 = new File(url2);
|
132
|
+
|
133
|
+
if(!file2.isDirectory()) return;
|
134
|
+
|
135
|
+
File files[] = file2.listFiles();
|
136
|
+
|
137
|
+
file_name = new String[files.length];
|
138
|
+
|
139
|
+
for (int i=0; i<files.length; i++) {
|
140
|
+
|
141
|
+
file_name[i] = files[i].getName();
|
142
|
+
|
143
|
+
File item = files[i];
|
144
|
+
|
145
|
+
if(item.isDirectory()) {
|
146
|
+
|
147
|
+
folder[i] = item.getName();
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
if (item.isFile()) {
|
152
|
+
|
153
|
+
name[i] = item.getName();
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
lst1.setListData(file_name);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
public class button1 implements ActionListener{
|
168
|
+
|
169
|
+
public void actionPerformed(ActionEvent e){
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
File file2 = new File(url1);
|
174
|
+
|
175
|
+
if(!file2.isDirectory()) return;
|
176
|
+
|
177
|
+
File files[] = file2.listFiles();
|
178
|
+
|
179
|
+
file_name = new String[files.length];
|
180
|
+
|
181
|
+
for (int i=0; i<files.length; i++) {
|
182
|
+
|
183
|
+
file_name[i] = files[i].getName();
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
JList lst0 = new JList(file_name);
|
188
|
+
|
189
|
+
JScrollPane lst1 = new JScrollPane(lst0);
|
190
|
+
|
191
|
+
lst1.setBounds(240, 150, 470,400);
|
192
|
+
|
193
|
+
add(lst1);
|
194
|
+
|
195
|
+
setVisible(true);
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
public static void main(String[] args) {
|
208
|
+
|
209
|
+
new TEST1();
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
}
|
216
|
+
|
1
|
-
[リンク内容](https://teratail.com/questions/169859)
|
217
|
+
```[リンク内容](https://teratail.com/questions/169859)
|
2
218
|
|
3
219
|
|
4
220
|
|
@@ -13,223 +229,3 @@
|
|
13
229
|
|
14
230
|
|
15
231
|
宜しくお願い致します。
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
<code>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
import java.awt.Font;
|
24
|
-
|
25
|
-
import java.awt.event.ActionEvent;
|
26
|
-
|
27
|
-
import java.awt.event.ActionListener;
|
28
|
-
|
29
|
-
import java.io.File;
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
import javax.swing.JButton;
|
34
|
-
|
35
|
-
import javax.swing.JFrame;
|
36
|
-
|
37
|
-
import javax.swing.JList;
|
38
|
-
|
39
|
-
import javax.swing.JScrollPane;
|
40
|
-
|
41
|
-
import javax.swing.event.ListSelectionEvent;
|
42
|
-
|
43
|
-
import javax.swing.event.ListSelectionListener;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
public class TEST1 extends JFrame implements ListSelectionListener {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
static String[] file_name;
|
52
|
-
|
53
|
-
String[] file_name2 = new String[200];
|
54
|
-
|
55
|
-
String[] folder = new String[200];
|
56
|
-
|
57
|
-
String[] name = new String[200];
|
58
|
-
|
59
|
-
static String url1;
|
60
|
-
|
61
|
-
String url2;
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
public TEST1() {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
url1 = "C:\Users\表示テスト\";
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
setSize(1300, 750);
|
76
|
-
|
77
|
-
setLayout(null);
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
button1();
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
list_sakusei();
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
//空のリストボックス作成
|
96
|
-
|
97
|
-
public void list_sakusei() {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
JList lst0 = new JList(file_name2);
|
102
|
-
|
103
|
-
lst0.addListSelectionListener(this);
|
104
|
-
|
105
|
-
JScrollPane lst1 = new JScrollPane(lst0);
|
106
|
-
|
107
|
-
lst1.setBounds(240, 150, 470,400);
|
108
|
-
|
109
|
-
getContentPane().add(lst1);
|
110
|
-
|
111
|
-
setVisible(true);
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
public void button1() {
|
122
|
-
|
123
|
-
JButton button1 = new JButton("ボタン1");
|
124
|
-
|
125
|
-
button1.setFont(new Font("Gothic", Font.PLAIN, 13));
|
126
|
-
|
127
|
-
button1.setBounds(80,150,150,30);
|
128
|
-
|
129
|
-
add(button1);
|
130
|
-
|
131
|
-
button1.addActionListener(new button1());
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
public void valueChanged(ListSelectionEvent e) {
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
JList lst1 = (JList)e.getSource();
|
144
|
-
|
145
|
-
url2 = url1+lst1.getSelectedValue();
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
//aフォルダの一覧を抽出する
|
150
|
-
|
151
|
-
File file2 = new File(url2);
|
152
|
-
|
153
|
-
if(!file2.isDirectory()) return;
|
154
|
-
|
155
|
-
File files[] = file2.listFiles();
|
156
|
-
|
157
|
-
file_name = new String[files.length];
|
158
|
-
|
159
|
-
for (int i=0; i<files.length; i++) {
|
160
|
-
|
161
|
-
file_name[i] = files[i].getName();
|
162
|
-
|
163
|
-
File item = files[i];
|
164
|
-
|
165
|
-
if(item.isDirectory()) {
|
166
|
-
|
167
|
-
folder[i] = item.getName();
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
if (item.isFile()) {
|
172
|
-
|
173
|
-
name[i] = item.getName();
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
lst1.setListData(file_name);
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
public class button1 implements ActionListener{
|
188
|
-
|
189
|
-
public void actionPerformed(ActionEvent e){
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
File file2 = new File(url1);
|
194
|
-
|
195
|
-
if(!file2.isDirectory()) return;
|
196
|
-
|
197
|
-
File files[] = file2.listFiles();
|
198
|
-
|
199
|
-
file_name = new String[files.length];
|
200
|
-
|
201
|
-
for (int i=0; i<files.length; i++) {
|
202
|
-
|
203
|
-
file_name[i] = files[i].getName();
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
JList lst0 = new JList(file_name);
|
208
|
-
|
209
|
-
JScrollPane lst1 = new JScrollPane(lst0);
|
210
|
-
|
211
|
-
lst1.setBounds(240, 150, 470,400);
|
212
|
-
|
213
|
-
add(lst1);
|
214
|
-
|
215
|
-
setVisible(true);
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
public static void main(String[] args) {
|
228
|
-
|
229
|
-
new TEST1();
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
}
|
1
タイトルの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Java
|
1
|
+
Java リストボックスをクリックしても認識出来ない
|
test
CHANGED
@@ -16,6 +16,10 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
<code>
|
20
|
+
|
21
|
+
|
22
|
+
|
19
23
|
import java.awt.Font;
|
20
24
|
|
21
25
|
import java.awt.event.ActionEvent;
|