Example usage for javax.swing JFileChooser getDialogTitle

List of usage examples for javax.swing JFileChooser getDialogTitle

Introduction

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

Prototype

public String getDialogTitle() 

Source Link

Document

Gets the string that goes in the JFileChooser's titlebar.

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(".");
    String f = fileChooser.getDialogTitle();

    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/*from w  w w  .j  a v  a 2 s  . c o  m*/
    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 />
 * /* w  w w . ja v a2  s.c  o m*/
 * @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) {
    }
}

From source file:Main.java

/**
 * Displays the given file chooser. Utility method for avoiding of memory leak in JDK
 * 1.3 {@link javax.swing.JFileChooser#showDialog}.
 *
 * @param chooser the file chooser to display.
 * @param parent the parent window./*from  w w  w.  j av  a  2  s  .  c o m*/
 * @param approveButtonText the text for the approve button.
 *
 * @return the return code of the chooser.
 */
public static final int showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText) {
    if (approveButtonText != null) {
        chooser.setApproveButtonText(approveButtonText);
        chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
    }

    Frame frame = (parent instanceof Frame) ? (Frame) parent
            : (Frame) javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, parent);
    String title = chooser.getDialogTitle();

    if (title == null) {
        title = chooser.getUI().getDialogTitle(chooser);
    }

    final JDialog dialog = new JDialog(frame, title, true);
    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(chooser, BorderLayout.CENTER);
    dialog.pack();
    dialog.setLocationRelativeTo(parent);
    chooser.rescanCurrentDirectory();

    final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION };

    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            if (ev.getActionCommand() == JFileChooser.APPROVE_SELECTION) {
                retValue[0] = JFileChooser.APPROVE_OPTION;
            }

            dialog.setVisible(false);
            dialog.dispose();
        }
    };

    chooser.addActionListener(l);
    dialog.show();

    return (retValue[0]);
}