-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChooser.java
More file actions
50 lines (44 loc) · 1.32 KB
/
Chooser.java
File metadata and controls
50 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cg;
/**
* Created by kreisso on 09.07.2018.
*/
import java.awt.event.*;
import javax.swing.*;
public class Chooser extends JPanel
implements ActionListener {
JButton go;
JTextField textField;
JFileChooser chooser;
String choosertitle;
int option;
public Chooser(int option) {
go = new JButton("...");
go.addActionListener(this);
textField = new JTextField(30);
this.option = option;
add(textField);
add(go);
}
public void actionPerformed(ActionEvent e) {
int result;
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(option);
//
// disable the "All files" option.
//
chooser.setAcceptAllFileFilterUsed(false);
//
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
textField.setText(chooser.getSelectedFile().toString());
System.out.println("getCurrentDirectory(): "
+ chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "
+ chooser.getSelectedFile());
}
else {
System.out.println("No Selection ");
}
}
}