Example usage for javax.swing JFileChooser rescanCurrentDirectory

List of usage examples for javax.swing JFileChooser rescanCurrentDirectory

Introduction

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

Prototype

public void rescanCurrentDirectory() 

Source Link

Document

Tells the UI to rescan its files list from the current directory.

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.rescanCurrentDirectory();
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/*ww w. j  av  a 2  s . c  om*/
    frame.setVisible(true);
}

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./*  w  w  w  .  j a v 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]);
}

From source file:org.zeromeaner.gui.reskin.StandaloneFrame.java

private void createCards() {
    introPanel = new StandaloneLicensePanel();
    content.add(introPanel, CARD_INTRO);

    playCard = new JPanel(new BorderLayout());
    content.add(playCard, CARD_PLAY);/*from ww  w . j  ava 2  s.c o m*/

    JPanel confirm = new JPanel(new GridBagLayout());
    JOptionPane option = new JOptionPane("A game is in open.  End this game?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!CARD_PLAY_END.equals(currentCard))
                return;
            if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) {
                gamePanel.shutdown();
                try {
                    gamePanel.shutdownWait();
                } catch (InterruptedException ie) {
                }
                contentCards.show(content, nextCard);
                currentCard = nextCard;
            }
            if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) {
                contentCards.show(content, CARD_PLAY);
                currentCard = CARD_PLAY;
                playButton.setSelected(true);
            }

            ((JOptionPane) evt.getSource()).setValue(-1);
        }
    });
    GridBagConstraints cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0);
    confirm.add(option, cx);
    content.add(confirm, CARD_PLAY_END);

    content.add(new StandaloneModeselectPanel(), CARD_MODESELECT);

    netplayCard = new JPanel(new BorderLayout());
    netplayCard.add(netLobby, BorderLayout.SOUTH);
    content.add(netplayCard, CARD_NETPLAY);

    confirm = new JPanel(new GridBagLayout());
    option = new JOptionPane("A netplay game is open.  End this game and disconnect?",
            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
    option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!CARD_NETPLAY_END.equals(currentCard))
                return;
            if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) {
                gamePanel.shutdown();
                try {
                    gamePanel.shutdownWait();
                } catch (InterruptedException ie) {
                }
                netLobby.disconnect();
                contentCards.show(content, nextCard);
                currentCard = nextCard;
            }
            if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) {
                contentCards.show(content, CARD_NETPLAY);
                currentCard = CARD_NETPLAY;
                netplayButton.setSelected(true);
            }

            ((JOptionPane) evt.getSource()).setValue(-1);
        }
    });
    cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE,
            new Insets(10, 10, 10, 10), 0, 0);
    confirm.add(option, cx);
    content.add(confirm, CARD_NETPLAY_END);

    StandaloneKeyConfig kc = new StandaloneKeyConfig(this);
    kc.load(0);
    content.add(kc, CARD_KEYS_1P);
    kc = new StandaloneKeyConfig(this);
    kc.load(1);
    content.add(kc, CARD_KEYS_2P);

    StandaloneGameTuningPanel gt = new StandaloneGameTuningPanel();
    gt.load(0);
    content.add(gt, CARD_TUNING_1P);
    gt = new StandaloneGameTuningPanel();
    gt.load(1);
    content.add(gt, CARD_TUNING_2P);

    StandaloneAISelectPanel ai = new StandaloneAISelectPanel();
    ai.load(0);
    content.add(ai, CARD_AI_1P);
    ai = new StandaloneAISelectPanel();
    ai.load(1);
    content.add(ai, CARD_AI_2P);

    StandaloneGeneralConfigPanel gc = new StandaloneGeneralConfigPanel();
    gc.load();
    content.add(gc, CARD_GENERAL);

    final JFileChooser fc = FileSystemViews.get().fileChooser("replay/");

    fc.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Zeromeaner Replay Files";
        }

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().endsWith(".zrep");
        }
    });

    fc.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION))
                return;
            JFileChooser fc = (JFileChooser) e.getSource();
            String path = fc.getSelectedFile().getPath();
            if (!path.contains("replay/"))
                path = "replay/" + path;
            startReplayGame(path);
        }
    });
    fc.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent e) {
            fc.rescanCurrentDirectory();
        }
    });
    content.add(fc, CARD_OPEN);

    content.add(new StandaloneFeedbackPanel(), CARD_FEEDBACK);
}