【发布时间】:2014-11-06 17:25:45
【问题描述】:
场景是,当一个单选按钮被选中时,我打开一个 JFileChooser 来选择一个应该是一些文件的目录。 我正在尝试显示一条错误消息,并且我想再次显示目录选择器。 这是代码(单选按钮更改时我调用的函数):
private void JFileChooserOpen(java.awt.event.ActionEvent evt) {
fileChooser.setCurrentDirectory(new java.io.File("."));
fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Select a directory");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(false);
int result = fileChooser.showOpenDialog(fileChooser);
if (result == JFileChooser.APPROVE_OPTION) {
// here I'm calling a function that searches for specific files.
// true these files are found, false, they are not.
if (checkTheDir(fileChooser.getSelectedFile()))
{
// assigning the path to a label
thePath.setText(fileChooser.getSelectedFile().toString());
}
else
{
// file not found
JOptionPane.showMessageDialog(null, "File GuiRap not found!",
"Controlla meglio", JOptionPane.WARNING_MESSAGE);
// what should I do, here, to open again the file dialog window?
// here I'm calling again this function, but surely is not a good practice!
JFileChooserOpen(evt);
}
// cancel button changes a radiobutton
} else if (result == JFileChooser.CANCEL_OPTION) {
rbnParams.setSelected(true);
}
}
非常感谢! F.
【问题讨论】:
标签: java swing jfilechooser