Example usage for javax.swing JFileChooser DIRECTORIES_ONLY

List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY

Introduction

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

Prototype

int DIRECTORIES_ONLY

To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.

Click Source Link

Document

Instruction to display only directories.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}

From source file:Main.java

public static void main(String[] a) {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    fileChooser.showSaveDialog(null);/*www .  j av  a  2 s . c  o  m*/
}

From source file:Main.java

public static void main(String[] a) {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    fileChooser.showOpenDialog(null);/*from  w  w  w.  j  a v a  2 s. c om*/
}

From source file:Main.java

public static void main(String s[]) {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("choosertitle");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
        System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
    } else {/* www  . jav a 2s .  co  m*/
        System.out.println("No Selection ");
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(false);
    fileChooser.setFileFilter(new FolderFilter());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.showOpenDialog(null);/*from w w  w  .  j a v  a 2s. com*/
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    final JButton button = new JButton("Select files...");
    button.addActionListener(e -> {//  ww  w .  java2s. c  om
        final JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(chooser.getFileSystemView().getParentDirectory(new File("C:\\")));
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.showDialog(button, "Select file");
    });
    panel.add(button);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:net.redstonelamp.gui.RedstoneLampGUI.java

public static void main(String[] args) {
    JFrame frame = new JFrame("RedstoneLamp");
    frame.setLayout(new GridLayout(2, 1));
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JLabel label = new JLabel("RedstoneLamp");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    frame.add(label);/*www  .j  a v  a2  s  .  c  om*/
    JPanel lowPanel = new JPanel();
    JPanel left = new JPanel();
    left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
    lowPanel.add(left);
    JPanel right = new JPanel();
    right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
    lowPanel.add(right);
    JButton openButton = new JButton("Open server at...");
    openButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(new File("."));
        chooser.setDialogTitle("Select RedstoneLamp server home");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showOpenDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (!jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. "
                        + "Would you like to install RedstoneLamp there?");
                if (result == JOptionPane.YES_OPTION) {
                    installCallback(frame, selected);
                }
                return;
            }
            frame.dispose();
            addHistory(selected);
            currentRoot = new ServerActivity(selected);
        }
    });
    right.add(openButton);
    JButton installButton = new JButton("Install server at...");
    installButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(".");
        chooser.setDialogTitle("Select directory to install server in");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showSaveDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. "
                        + "Are you sure you want to reinstall RedstoneLamp there?");
                if (result == JOptionPane.NO_OPTION) {
                    frame.dispose();
                    addHistory(selected);
                    currentRoot = new ServerActivity(selected);
                    return;
                }
            }
            installCallback(frame, selected);
        }
    });
    frame.add(lowPanel);
    frame.pack();
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dimension.width / 2 - frame.getSize().width / 2,
            dimension.height / 2 - frame.getSize().height / 2);
    frame.setVisible(true);
}

From source file:net.sf.vntconverter.VntConverter.java

/**
 * Fhrt den VntConverter mit den angegebnen Optionen aus.
 */// w w w. j  a v  a  2s  . co m
public static void main(String[] args) {
    try {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            // Wenn nicht, dann nicht ...
        }
        JFileChooser fileChooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files (txt) and memo files (vnt)",
                "txt", "vnt");
        fileChooser.setCurrentDirectory(new java.io.File("."));
        fileChooser.setDialogTitle("Choose files to convert ...");
        fileChooser.setFileFilter(filter);
        fileChooser.setMultiSelectionEnabled(true);
        if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            JFileChooser directoryChooser = new JFileChooser();
            directoryChooser.setCurrentDirectory(new java.io.File("."));
            directoryChooser.setDialogTitle("Choose target directory ...");
            directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            directoryChooser.setAcceptAllFileFilterUsed(false);
            if (directoryChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                VntConverter converter = new VntConverter();
                String targetDirectoy = directoryChooser.getSelectedFile().getAbsolutePath();
                System.out.println(targetDirectoy);
                for (File file : fileChooser.getSelectedFiles()) {
                    if (file.getName().endsWith(".txt")) {
                        converter.encode(file,
                                new File(targetDirectoy + "\\" + file.getName().replace(".txt", ".vnt")));
                    } else if (file.getName().endsWith(".vnt")) {
                        converter.decode(file,
                                new File(targetDirectoy + "\\" + file.getName().replace(".vnt", ".txt")));
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception caught", e);
    }
}

From source file:Main.java

public static File chooseDirectory(Component parentComponent, String title) {
    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    jfc.showDialog(parentComponent, title);
    return jfc.getSelectedFile();
}

From source file:Main.java

public static File chooseDir(Component parent, String title) {
    JFileChooser chooser = new JFileChooser();
    // chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle(title);/*  w  w  w  .  j  a  v  a 2 s.  com*/
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonText("Select Dir");
    return chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION ? chooser.getSelectedFile() : null;
}