    protected static JPanel customFileChooser(final JDialog dlg, final JFileChooser chooser, final Action action) {
	Insets insets = null;
	if (chooser.getBorder() instanceof EmptyBorder)
	    insets = ((EmptyBorder)chooser.getBorder()).getBorderInsets();
	chooser.setControlButtonsAreShown(false);
	chooser.setApproveButtonText((String)action.getValue(Action.NAME));
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.add(chooser);
	JPanel contentpane = new JPanel();
	contentpane.setLayout(new BoxLayout(contentpane, BoxLayout.Y_AXIS));
	if (insets!=null) contentpane.setBorder(BorderFactory.createEmptyBorder(0, insets.left, 0, insets.right));
	panel.add(contentpane);
	JPanel btns = new JPanel();
	if (insets!=null) btns.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
	btns.add(Box.createHorizontalGlue());
	btns.setLayout(new BoxLayout(btns, BoxLayout.X_AXIS));
	final JButton activate = new JButton(new AbstractAction((String)action.getValue(Action.NAME)) {
	    public void actionPerformed(ActionEvent e) {
		chooser.approveSelection();
	    }
	});
	btns.add(activate);
	final JButton cancel = new JButton(new AbstractAction("Cancel") {
	    public void actionPerformed(ActionEvent e) {
		chooser.cancelSelection();
	    }
	});
	btns.add(cancel);
	panel.add(btns);
	dlg.getContentPane().add(panel);
	dlg.getRootPane().setDefaultButton(activate);
	dlg.setModal(true);
	chooser.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		if (JFileChooser.APPROVE_SELECTION.equals(e.getActionCommand())) {
		    if (chooser.getUI() instanceof BasicFileChooserUI) {
		        BasicFileChooserUI ui = (BasicFileChooserUI)chooser.getUI();
		        chooser.setSelectedFile(new File(ui.getFileName()));
		    }
		    action.actionPerformed(e);
		}
		dlg.removeAll();
		dlg.dispose();
	    }
	});
	return contentpane;
    }

    protected static JPanel customFileChooser(final JDialog dlg, final JFileChooser chooser, final Action action) {
	Insets insets = null;
	if (chooser.getBorder() instanceof EmptyBorder)
	    insets = ((EmptyBorder)chooser.getBorder()).getBorderInsets();
	chooser.setControlButtonsAreShown(false);
	chooser.setApproveButtonText((String)action.getValue(Action.NAME));
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.add(chooser);
	JPanel contentpane = new JPanel();
	contentpane.setLayout(new BoxLayout(contentpane, BoxLayout.Y_AXIS));
	if (insets!=null) contentpane.setBorder(BorderFactory.createEmptyBorder(0, insets.left, 0, insets.right));
	panel.add(contentpane);
	JPanel btns = new JPanel();
	if (insets!=null) btns.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
	btns.add(Box.createHorizontalGlue());
	btns.setLayout(new BoxLayout(btns, BoxLayout.X_AXIS));
	final JButton activate = new JButton(new AbstractAction((String)action.getValue(Action.NAME)) {
	    public void actionPerformed(ActionEvent e) {
		chooser.approveSelection();
	    }
	});
	btns.add(activate);
	final JButton cancel = new JButton(new AbstractAction("Cancel") {
	    public void actionPerformed(ActionEvent e) {
		chooser.cancelSelection();
	    }
	});
	btns.add(cancel);
	panel.add(btns);
	dlg.getContentPane().add(panel);
	dlg.getRootPane().setDefaultButton(activate);
	dlg.setModal(true);
	chooser.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		if (JFileChooser.APPROVE_SELECTION.equals(e.getActionCommand())) {
		    if (chooser.getUI() instanceof BasicFileChooserUI) {
		        BasicFileChooserUI ui = (BasicFileChooserUI)chooser.getUI();
		        File f = new File(chooser.getCurrentDirectory(), ui.getFileName());
		        chooser.setSelectedFile(f);
		    }
		    action.actionPerformed(e);
		}
		dlg.removeAll();
		dlg.dispose();
	    }
	});
	return contentpane;
    }
