M
M0l0ch
Gast
Ein Filechooser ist sichtbar. Der user drückt rechts oben auf das x und schließt somit den Dialog. Wie kann ich auf dieses "X" drücken abfragen um meinen eigenen code auszuführen?
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
public int showDialog(Component parent, String approveButtonText)
throws HeadlessException {
if(approveButtonText != null) {
setApproveButtonText(approveButtonText);
setDialogType(CUSTOM_DIALOG);
}
dialog = createDialog(parent);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
returnValue = CANCEL_OPTION;
}
});
returnValue = ERROR_OPTION;
rescanCurrentDirectory();
dialog.show();
dialog.dispose();
dialog = null;
return returnValue;
}
protected JDialog createDialog(Component parent) throws HeadlessException {
Frame frame = parent instanceof Frame ? (Frame) parent
: (Frame)SwingUtilities.getAncestorOfClass(Frame.class, parent);
String title = getUI().getDialogTitle(this);
getAccessibleContext().setAccessibleDescription(title);
JDialog dialog = new JDialog(frame, title, true);
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(this, BorderLayout.CENTER);
if (JDialog.isDefaultLookAndFeelDecorated()) {
boolean supportsWindowDecorations =
UIManager.getLookAndFeel().getSupportsWindowDecorations();
if (supportsWindowDecorations) {
dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
}
}
dialog.pack();
dialog.setLocationRelativeTo(parent);
return dialog;
}