1 | package geniusweb.simplerunner.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import java.awt.event.ActionListener;
|
---|
6 |
|
---|
7 | import javax.swing.JButton;
|
---|
8 | import javax.swing.JFileChooser;
|
---|
9 | import javax.swing.JPanel;
|
---|
10 | import javax.swing.JTextField;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * one-line panel with on left the chosen file and on the right a "Browse"
|
---|
14 | * button. If you click browse button you can browse for a file. You can also
|
---|
15 | * just type the file location.
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class MyFileChooser extends JPanel {
|
---|
19 | private JTextField filenamearea = new JTextField("select a file");
|
---|
20 | private JButton browsebutton = new JButton("Browse");
|
---|
21 |
|
---|
22 | public MyFileChooser() {
|
---|
23 | setLayout(new BorderLayout());
|
---|
24 | add(filenamearea, BorderLayout.CENTER);
|
---|
25 | add(browsebutton, BorderLayout.EAST);
|
---|
26 | browsebutton.addActionListener(new ActionListener() {
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public void actionPerformed(ActionEvent e) {
|
---|
30 | JFileChooser fc = new JFileChooser();
|
---|
31 | int returnVal = fc.showOpenDialog(browsebutton);
|
---|
32 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
33 | filenamearea
|
---|
34 | .setText(fc.getSelectedFile().getAbsolutePath());
|
---|
35 | }
|
---|
36 | }
|
---|
37 | });
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | public String getFile() {
|
---|
42 | return filenamearea.getText();
|
---|
43 | }
|
---|
44 | }
|
---|