시나리오는 라디오 버튼을 선택하면 JFileChooser를 열어 DIRECTORY를 선택해야합니다. 오류 메시지를 표시하려고하는데 디렉토리 선택기를 다시 표시하려고합니다. 이 코드 (I 전화 기능 때 라디오 버튼 변경)입니다 :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.
완전한 예를 볼 수있다 [여기] (http://stackoverflow.com/a/4054307/230513). – trashgod