Example usage for javax.swing JFileChooser putClientProperty

List of usage examples for javax.swing JFileChooser putClientProperty

Introduction

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

Prototype

public final void putClientProperty(Object key, Object value) 

Source Link

Document

Adds an arbitrary key/value "client property" to this component.

Usage

From source file:pcgen.gui2.tools.DesktopBrowserLauncher.java

/**
 * Sets the default browser./*from  w w  w  .j  a  v a 2 s  .c o  m*/
 */
public static void selectDefaultBrowser() {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Find and select your preferred html browser.");

    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
        fc.putClientProperty("JFileChooser.appBundleIsTraversable", "never");
    }

    if (PCGenSettings.getBrowserPath() != null) {
        fc.setCurrentDirectory(new File(PCGenSettings.getBrowserPath()));
    }

    final int returnVal = fc.showOpenDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = fc.getSelectedFile();
        PCGenSettings.OPTIONS_CONTEXT.setProperty(PCGenSettings.BROWSER_PATH, file.getAbsolutePath());
    }
}

From source file:pcgen.gui2.tools.Utility.java

/**
 * Sets the default browser.// w  ww.j av a2s.c om
 *
 * @param parent The component to show the dialog over.
 */
public static void selectDefaultBrowser(Component parent) {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Find and select your preferred html browser.");

    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
        // On MacOS X, do not traverse file bundles
        fc.putClientProperty("JFileChooser.appBundleIsTraversable", "never");
    }

    if (PCGenSettings.getBrowserPath() == null) {
        //No action, as we have no idea what a good default would be...
    } else {
        fc.setCurrentDirectory(new File(PCGenSettings.getBrowserPath()));
    }

    final int returnVal = fc.showOpenDialog(parent);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = fc.getSelectedFile();
        PCGenSettings.OPTIONS_CONTEXT.setProperty(PCGenSettings.BROWSER_PATH, file.getAbsolutePath());
    }
}