Java JTextField browseFileForField(JTextField textField, JFileChooser fileChooser, Component parent)

Here you can find the source of browseFileForField(JTextField textField, JFileChooser fileChooser, Component parent)

Description

Uses the fileChooser to browse a (not further filtered) file and put the path to the file in the given JTextField .

License

Open Source License

Parameter

Parameter Description
textField a parameter

Declaration

public static void browseFileForField(JTextField textField, JFileChooser fileChooser, Component parent) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;
import java.io.File;

import javax.swing.JFileChooser;

import javax.swing.JTextField;

public class Main {
    /**//from  ww w . j  a  v  a  2  s .co m
     * Uses the fileChooser to browse a (not further filtered) file and put the
     * path to the file in the given {@link JTextField}.
     * 
     * @param textField
     */
    public static void browseFileForField(JTextField textField, JFileChooser fileChooser, Component parent) {
        fileChooser.setMultiSelectionEnabled(false);
        int returnVal = fileChooser.showOpenDialog(parent);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();

            textField.setText(file.getAbsolutePath());
        }
    }
}

Related

  1. adjustTextToRight(JTextField textField)
  2. applyDefaultProperties(final JTextField comp)
  3. AreAllTextFieldsFilled(javax.swing.JTextField[] tfs)
  4. badField(JTextField field)
  5. bindPropertyChangeListener(final JTextField field, final String name, final PropertyChangeListener listener)
  6. checkJTextFieldNotEmpty(javax.swing.JTextField field, javax.swing.JLabel promptName, ArrayList errors)
  7. cleanTextFields(JTextField... textFields)
  8. createBrowseButton(final JTextField txtInput, final Window parent, final boolean directoryBrowser)
  9. createFieldWithLabel(String label, JTextField textField)