JFileChooser의 showOpenDialog 메소드를 사용하여 파일을 엽니 다.승인 또는 취소 버튼을 눌렀을 때 JFileChooser가 닫히지 않게하는 방법은 무엇입니까?
Approve 버튼을 클릭하고 청취자를 완료 한 후 이 닫히는 것을 막기 위해 JFileChooser
의 Approve 버튼에 ActionListener를 연결하는 방법 및이 대화 상자를 중지하는 방법. 지금은
나는이 :
public class MainFileChooser extends JFileChooser {
private FileFilter plainFilter;
public MainFileChooser() {
super.setMultiSelectionEnabled(true);
super.setAcceptAllFileFilterUsed(false);
plainFilter = new PlainFilter();
}
public int showOpenFileDialog() {
ActionListener actionListener = null;
// JDialog openFileDialog = super.createDialog(getParent());
super.addActionListener(actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File[] selectedFiles = MainFileChooser.this.getSelectedFiles();
for (File file : selectedFiles) {
if (!file.exists()) {
JOptionPane.showMessageDialog(getParent(), file.getName() + " does not exist!",
"File is not found", JOptionPane.ERROR_MESSAGE);
}
}
}
});
super.setFileFilter(plainFilter);
int userOption = super.showOpenDialog(MainFrame.getInstance().getMainFrame());
super.removeActionListener(actionListener);
return userOption;
}
방법 showOpenFileDialog
는 대화 상자가 나타납니다 내가 버튼 actionListener
승인 누를 때 호출되고 파일이 다음 존재하지 않는 경우 오류 메시지가 팝업됩니다.
하지만 JFileChooser가 닫혀 있습니다. 파일이 존재하지 않으면 JFileChooser를 열어두기를 원합니다!
감사합니다.
확인 새 응답을! –