Example usage for javax.swing JFileChooser removeActionListener

List of usage examples for javax.swing JFileChooser removeActionListener

Introduction

In this page you can find the example usage for javax.swing JFileChooser removeActionListener.

Prototype

public void removeActionListener(ActionListener l) 

Source Link

Document

Removes an ActionListener from the file chooser.

Usage

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(false);
    frame.add(fileChooser, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
                File selectedFile = theFileChooser.getSelectedFile();
                System.out.println(selectedFile.getParent());
                System.out.println(selectedFile.getName());
            } else if (command.equals(JFileChooser.CANCEL_SELECTION)) {
                System.out.println(JFileChooser.CANCEL_SELECTION);
            }/*from  w  w w  . j a v  a 2s  .com*/
        }
    };
    fileChooser.addActionListener(actionListener);
    fileChooser.removeActionListener(actionListener);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Displays a specified <code>JFileChooser</code> in a JInternalFrame. <br />
 * The JInternalFrame will close when the dialog is closed. <br />
 * /*  ww w  .j  a  v  a2 s.  c om*/
 * @param desktop the JDesktopPane on which to display the JFileChooser
 * @param ch the JFileChooser to display
 */
public static void showInternalFileChooser(JDesktopPane desktop, final JFileChooser ch) {
    final JInternalFrame frm = new JInternalFrame(ch.getDialogTitle());
    frm.setClosable(true);
    frm.setResizable(true);
    frm.setLayout(new BorderLayout());
    frm.add(ch, BorderLayout.CENTER);
    frm.setVisible(true);

    frm.pack();

    Dimension size = frm.getSize();
    frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2);
    desktop.add(frm, 0);

    ch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            frm.dispose();
            ch.removeActionListener(this);
        }
    });

    try {
        frm.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
    }
}