1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| JFileChooser jfc = new JFileChooser(){
JDialog dialog;
int 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);
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;
}
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;
dialog.dispose();
dialog = null;
}
});
returnValue = ERROR_OPTION;
rescanCurrentDirectory();
dialog.show();
//dialog.dispose();
//dialog = null;
return 0;
}
}; |