FileChooser¿?
Publicado por miguel (14 intervenciones) el 23/11/2017 22:24:34
Hola a todos no tengo mucha practica en java swing y tengo un problema tal ves tonto pero no puedo resolverlo,
trata de que este metodo actionPerformed(ActionEvent e) meda error en este fragmento "showOpenDialog"
Alguien me puede orientarme?
trata de que este metodo actionPerformed(ActionEvent e) meda error en este fragmento "showOpenDialog"
Alguien me puede orientarme?
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Index extends JFrame {
JTextArea texto;
JFileChooser chooser;
String choosertitle;
class MenuActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//
// disable the "All files" option.
//
chooser.setAcceptAllFileFilterUsed(false);
//
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): "
+ chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "
+ chooser.getSelectedFile());
}
else {
JOptionPane.showMessageDialog(null, "No selection index", "Ups!", JOptionPane.OK_CANCEL_OPTION);
}
}
}
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
Index frame = new Index();
frame.setTitle("M&P LIBRARY");
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public Index() {
//Parametros asociados a la ventana
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 950, 700);
contentPane = new JPanel();
contentPane.setLayout(null);
setContentPane(contentPane);
//Creamos un menu y modificamos el icono
JMenuBar MnuBar = new JMenuBar();
JMenu Mnu=new JMenu("Index", true);
Mnu.add("Create new index");
Mnu.addActionListener(new MenuActionListener());
MnuBar.add(Mnu);
setJMenuBar(MnuBar);
JLabel lbl1 = new JLabel();
lbl1.setText("Search for:");
lbl1.setBounds(250, 20, 70, 30);
contentPane.add(lbl1);
JTextField txt1 = new JTextField();
txt1.setBounds(320, 24, 200, 25);
contentPane.add(txt1);
JButton btn1 = new JButton();
btn1.setText("Search");
btn1.setBounds(525, 24, 90, 25);
contentPane.add(btn1);
JScrollPane textScroll=new JScrollPane(texto,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textScroll.setBounds(20, 100, 900, 500);
contentPane.add(textScroll);
}
}
Valora esta pregunta
0