Here you can find the source of wrapWithFileChooser(final Component aParent, final JTextField aTextField, final int aFileSelectionMode)
Parameter | Description |
---|---|
aParent | the parent to the chooser dialog |
aTextField | the text field representing the file choice |
aFileSelectionMode | the argument to pass to javax.swing.JFileChooser#setFileSelectionMode . |
public static Component wrapWithFileChooser(final Component aParent, final JTextField aTextField, final int aFileSelectionMode)
//package com.java2s; //License from project: Apache License import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.JTextField; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Main { /**//from w ww. j a v a 2 s . co m * @param aParent the parent to the chooser dialog * @param aTextField the text field representing the file choice * @param dotDotDot the chooser popup button * @param aFileSelectionMode the argument to pass to {@link javax.swing.JFileChooser#setFileSelectionMode}. */ public static Component wrapWithFileChooser(final Component aParent, final JTextField aTextField, final JButton dotDotDot, final int aFileSelectionMode) { JPanel pane = new JPanel(new BorderLayout()); pane.add(aTextField, BorderLayout.CENTER); pane.add(dotDotDot, BorderLayout.EAST); dotDotDot.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(aTextField.getText()); chooser.setFileSelectionMode(aFileSelectionMode); int choice = chooser.showDialog(aParent, "Select"); if (choice == JFileChooser.APPROVE_OPTION) { aTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); return pane; } /** * @param aParent the parent to the chooser dialog * @param aTextField the text field representing the file choice * @param aFileSelectionMode the argument to pass to {@link javax.swing.JFileChooser#setFileSelectionMode}. */ public static Component wrapWithFileChooser(final Component aParent, final JTextField aTextField, final int aFileSelectionMode) { return wrapWithFileChooser(aParent, aTextField, new JButton("..."), aFileSelectionMode); } }