final JFileChooser chooser = new JFileChooser();
JOptionPane.showInternalOptionDialog(this, chooser, "Browse",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
new Object[]{}, null);
chooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION))
System.out.println("File selected: " +
chooser.getSelectedFile());
//code to close here
} else {
//code to close here
}
}
});
这段代码看起来很奇怪,但它只是我程序的一部分。我使用全屏GraphicsDevice
。我将文件选择器放在内部JOptionPane中以保留全屏窗口。现在我想以编程方式关闭JOptionPane内部本身,而不是在我的 actionlistener 中关闭整个应用程序。怎么做到呢?