Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

In this page you can find the example usage for javax.swing JTextField setText.

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:com._17od.upm.gui.AccountDialog.java

/**
 * This method takes in a JTextField object and then sets the text of that
 * text field to the contents of the system clipboard.
 * //  w ww.  jav a  2 s  .  c  o  m
 * @param textField
 */
public void pasteToTextField(JTextField textField) {
    String text = "";
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipText = clipboard.getContents(null);
    if ((clipText != null) && clipText.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            text = (String) clipText.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    textField.setText(text);
}

From source file:es.emergya.ui.gis.ControlPanel.java

public ControlPanel(final CustomMapView view) {
    super(new FlowLayout(FlowLayout.LEADING, 12, 0));
    this.view = view;
    // Posicion: panel con un label de icono y un textfield
    JPanel posPanel = new JPanel();
    posPanel.setOpaque(true);/*from   w w  w. j a  v a2s  .c o  m*/
    posPanel.setVisible(true);
    JLabel mouseLocIcon = new JLabel(LogicConstants.getIcon("map_icon_coordenadas"));
    posPanel.add(mouseLocIcon);
    final JTextField posField = new JTextField(15);
    posField.setEditable(false);
    posField.setBorder(null);
    posField.setForeground(UIManager.getColor("Label.foreground"));
    posField.setFont(UIManager.getFont("Label.font"));
    posPanel.add(posField);
    view.addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseMoved(MouseEvent e) {
            LatLon ll = ((ICustomMapView) e.getSource()).getLatLon(e.getX(), e.getY());
            String position = "";
            String format = LogicConstants.get("FORMATO_COORDENADAS_MAPA", "UTM");
            if (format.equals(LogicConstants.COORD_UTM)) {
                UTM u = new UTM(LogicConstants.getInt("ZONA_UTM"));
                EastNorth en = u.latlon2eastNorth(ll);
                position = String.format("x: %.1f y: %.1f", en.getX(), en.getY());
            } else {
                position = String.format("Lat: %.4f Lon: %.4f", ll.lat(), ll.lon());
            }

            posField.setText(position);
            validate();
        }

        @Override
        public void mouseDragged(MouseEvent e) {
        }
    });
    posPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    add(posPanel);

    // Panel de centrado: label, desplegable y parte cambiante
    JPanel centerPanel = new JPanel();
    centerPanel.add(new JLabel(i18n.getString("map.centerIn")));
    centerOptions = new JComboBox(new String[] { i18n.getString("map.street"), i18n.getString("map.resource"),
            i18n.getString("map.incidence"), i18n.getString("map.location") });
    centerPanel.add(centerOptions);

    centerData = new JPanel(new CardLayout());
    centerPanel.add(centerData);

    JPanel centerStreet = new JPanel();
    street = new JTextField(30);
    street.setName(i18n.getString("map.street"));
    autocompleteKeyListener = new AutocompleteKeyListener(street);
    street.addKeyListener(autocompleteKeyListener);
    street.addActionListener(this);
    centerStreet.add(street);
    centerData.add(centerStreet, i18n.getString("map.street"));

    JPanel centerResource = new JPanel();
    resources = new JComboBox(avaliableResources);
    resources.setName(i18n.getString("map.resource"));
    resources.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    resources.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            isComboResourcesShowing = true;
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            isComboResourcesShowing = false;
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // view.repaint();
        }
    });
    centerResource.add(resources);
    centerData.add(centerResource, i18n.getString("map.resource"));

    centerResource = new JPanel();
    incidences = new JComboBox(avaliableIncidences);
    incidences.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    incidences.setName(i18n.getString("map.incidence"));
    incidences.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            isComboIncidencesShowing = true;
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            isComboIncidencesShowing = false;
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {

        }
    });
    centerResource.add(incidences);
    centerData.add(centerResource, i18n.getString("map.incidence"));

    JPanel centerLocation = new JPanel();
    cx = new JTextField(10);
    cx.setName("x");
    cx.addActionListener(this);
    centerLocation.add(cx);
    cy = new JTextField(10);
    cy.setName("y");
    cy.addActionListener(this);
    centerLocation.add(cy);
    centerData.add(centerLocation, i18n.getString("map.location"));

    centerOptions.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            ((CardLayout) centerData.getLayout()).show(centerData, (String) e.getItem());
        }
    });

    JButton centerButton = new JButton(i18n.getString("map.center"));
    centerButton.addActionListener(this);
    centerPanel.add(centerButton);
    add(centerPanel);

}

From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java

/**
 * @return/*from   w w w  . j a v a  2s  .  com*/
 */
private Pair<String, String> getExportLoginCreds(final String userName, final boolean wasInError) {
    loginBtn.setEnabled(false);

    loadAndPushResourceBundle(RESOURCE_NAME);
    try {
        final JTextField userNameTF = createTextField(15);
        final JPasswordField passwordTF = createPasswordField();
        final JLabel statusLbl = createLabel(" ");

        if (wasInError) {
            setErrorMsg(statusLbl, "Your username or password was not correct.");
        }

        ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd);
        JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT",
                "Password", passwordTF, statusLbl, imgIcon);
        if (!iPadDBExporter.IS_TESTING) // ZZZ
        {
            while (true) {
                userNameTF.setText(userName);
                final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(),
                        getResourceString("iPad Cloud Login"), true, CustomDialog.OKCANCELAPPLY, loginPanel) {
                    @Override
                    protected void applyButtonPressed() {
                        String uName = userNameTF.getText();
                        if (iPadCloud.isUserNameOK(uName)) {
                            setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName));
                        } else {
                            super.applyButtonPressed();
                        }
                    }
                };
                KeyAdapter ka = new KeyAdapter() {
                    @Override
                    public void keyReleased(KeyEvent e) {
                        super.keyReleased(e);
                        boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText())
                                && StringUtils.isNotEmpty(new String(passwordTF.getPassword()));
                        dlg.getOkBtn().setEnabled(isOK);
                        dlg.getApplyBtn().setEnabled(isOK);
                    }
                };
                userNameTF.addKeyListener(ka);
                passwordTF.addKeyListener(ka);

                dlg.setCloseOnApplyClk(true);
                dlg.setApplyLabel(getResourceString("NEW_USER"));
                dlg.setOkLabel(getResourceString("LOGIN"));

                dlg.createUI();

                boolean enableBtns = StringUtils.isNotEmpty(userName);
                dlg.getOkBtn().setEnabled(enableBtns);
                dlg.getApplyBtn().setEnabled(enableBtns);

                centerAndShow(dlg);

                if (!dlg.isCancelled()) {
                    boolean isOK = true;
                    String uName = userNameTF.getText();
                    String pwd = new String(passwordTF.getPassword());
                    if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) {
                        Institution inst = iPadDBExporter.getCurrentInstitution();
                        if (!iPadCloud.addNewUser(uName, pwd, inst.getGuid())) {
                            setErrorMsg(statusLbl, kErrorCreatingAcctMsg);
                            isOK = false;
                        }
                    }
                    if (isOK) {
                        return new Pair<String, String>(uName, pwd);
                    }
                } else {
                    return null;
                }
            }
        }
        return null;//new Pair<String, String>("testuser@ku.edu", "testuser@ku.edu");

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        popResourceBundle();
        loginBtn.setEnabled(true);
    }
    return null;
}

From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java

private JTextField createSetsTextField() {
    final JTextField textField = new JTextField(30);

    textField.addFocusListener(new FocusAdapter() {
        @Override//from  www .  j  av a 2 s.co  m
        public void focusGained(FocusEvent e) {
            e.getOppositeComponent().requestFocus();

            // get the frame the panel is embedded in
            Component currentComponent = HarvesterPanel.this;
            while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) {
                currentComponent = currentComponent.getParent();
            }
            final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent : null;

            if (HarvesterPanel.this.availableSets == null) {
                LocalizedOptionPane.showMessageDialog(parentFrame, "No_setnames_retrieved",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            String[] selectedSets = textField.getText().split(","); //$NON-NLS-1$

            for (int i = 0; i < selectedSets.length; i++) {
                selectedSets[i] = selectedSets[i].trim();
            }

            SetSelectionWindow ssw = new SetSelectionWindow(parentFrame, HarvesterPanel.this.availableSets,
                    selectedSets);
            ssw.setVisible(true);

            textField.setText(StringUtils.join(ssw.getSelectedSets(), ", "));
        }
    });

    return textField;
}

From source file:configuration.Util.java

public static void updateSavedProperties(workflow_properties properties, ArrayList<HashMap> listDicts,
        JTextField Editor_name) {
    // Values//  w w  w .  j ava  2  s . c o m
    uspBoxSpinVal(properties, listDicts.get(0));
    uspBoxTextVal(properties, listDicts.get(1));
    uspBoxComboboxVal(properties, listDicts.get(2));
    uspRButSpinVal(properties, listDicts.get(3));
    uspRButTextVal(properties, listDicts.get(4));
    // Button, boxes, values
    uspBoxSpin(properties, listDicts.get(0));
    uspBoxText(properties, listDicts.get(1));
    uspBoxCombo(properties, listDicts.get(2));
    uspRButSpin(properties, listDicts.get(3));
    uspRButText(properties, listDicts.get(4));
    if (Editor_name != null)
        Editor_name.setText(properties.getName());
}

From source file:ir.ac.iust.nlp.postagger.POSTaggerForm.java

private void setupDrop(final JTextField text, final boolean isInput) {
    FileDrop fd = new FileDrop(null, text, new FileDrop.Listener() {
        @Override//from  w  w w .  j ava 2s. co m
        public void filesDropped(java.io.File[] files) {
            if (files.length > 0) {
                try {
                    if (isInput == true) {
                        boolean dropped = false;
                        for (int i = 0; i < files.length; i++) {
                            if (files[i].isFile()) {
                                text.setText(files[i].getCanonicalPath());
                                dropped = true;
                                break;
                            }
                        }
                        if (dropped == false) {
                            JOptionPane.showMessageDialog(null, "File needed.");
                        }
                    } else {
                        if (files[0].isFile()) {
                            files[0] = files[0].getParentFile();
                        }

                        text.setText(files[0].getCanonicalPath() + File.separator);
                    }
                } // end try
                catch (java.io.IOException e) {
                }
            } // end for: through each dropped file
        } // end filesDropped
    }); // end FileDrop.Listener
}

From source file:DesktopAppTest.java

public DesktopAppFrame() {
    setLayout(new GridBagLayout());
    final JFileChooser chooser = new JFileChooser();
    JButton fileChooserButton = new JButton("...");
    final JTextField fileField = new JTextField(20);
    fileField.setEditable(false);/*from   w  w  w .ja va 2 s.  c o  m*/
    JButton openButton = new JButton("Open");
    JButton editButton = new JButton("Edit");
    JButton printButton = new JButton("Print");
    final JTextField browseField = new JTextField();
    JButton browseButton = new JButton("Browse");
    final JTextField toField = new JTextField();
    final JTextField subjectField = new JTextField();
    JButton mailButton = new JButton("Mail");

    openButton.setEnabled(false);
    editButton.setEnabled(false);
    printButton.setEnabled(false);
    browseButton.setEnabled(false);
    mailButton.setEnabled(false);

    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN))
            openButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.EDIT))
            editButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.PRINT))
            printButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.BROWSE))
            browseButton.setEnabled(true);
        if (desktop.isSupported(Desktop.Action.MAIL))
            mailButton.setEnabled(true);
    }

    fileChooserButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION)
                fileField.setText(chooser.getSelectedFile().getAbsolutePath());
        }
    });

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().open(chooser.getSelectedFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    editButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().edit(chooser.getSelectedFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    printButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().print(chooser.getSelectedFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    browseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(new URI(browseField.getText()));
            } catch (URISyntaxException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    mailButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                String subject = percentEncode(subjectField.getText());
                URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject);

                System.out.println(uri);
                Desktop.getDesktop().mail(uri);
            } catch (URISyntaxException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });

    JPanel buttonPanel = new JPanel();
    ((FlowLayout) buttonPanel.getLayout()).setHgap(2);
    buttonPanel.add(openButton);
    buttonPanel.add(editButton);
    buttonPanel.add(printButton);

    add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2));
    add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL));
    add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0));
    add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL));
    add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL));
    add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL));

    pack();
}

From source file:edu.umich.robot.GuiApplication.java

public void createSuperdroidRobotDialog() {
    final Pose pose = new Pose();

    FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu",
            "pref, 2dlu, pref, 2dlu, pref");

    layout.setRowGroups(new int[][] { { 1, 3 } });

    final JDialog dialog = new JDialog(frame, "Create Superdroid Robot", true);
    dialog.setLayout(layout);/*from  www  . jav  a2s .c om*/
    final JTextField name = new JTextField();
    final JTextField x = new JTextField(Double.toString((pose.getX())));
    final JTextField y = new JTextField(Double.toString((pose.getY())));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(name, cc.xyw(3, 1, 5));
    dialog.add(new JLabel("x"), cc.xy(1, 3));
    dialog.add(x, cc.xy(3, 3));
    dialog.add(new JLabel("y"), cc.xy(5, 3));
    dialog.add(y, cc.xy(7, 3));
    dialog.add(cancel, cc.xyw(1, 5, 3));
    dialog.add(ok, cc.xyw(5, 5, 3));

    x.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setX(Double.parseDouble(x.getText()));
            } catch (NumberFormatException ex) {
                x.setText(Double.toString(pose.getX()));
            }
        }
    });

    y.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setY(Double.parseDouble(y.getText()));
            } catch (NumberFormatException ex) {
                y.setText(Double.toString(pose.getX()));
            }
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = name.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Create Superdroid: robot name empty");
                return;
            }
            for (char c : robotName.toCharArray())
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create Superdroid: illegal robot name");
                    return;
                }

            controller.createSuperdroidRobot(robotName, pose, true);
            controller.createSimSuperdroid(robotName);
            dialog.dispose();
        }
    };
    name.addActionListener(okListener);
    x.addActionListener(okListener);
    y.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.setLocationRelativeTo(frame);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:edu.umich.robot.GuiApplication.java

/**
 * <p>//from   w w  w .j  ava2  s .c  o  m
 * Pops up a window to create a new splinter robot to add to the simulation.
 */
public void createSplinterRobotDialog() {
    final Pose pose = new Pose();

    FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu",
            "pref, 2dlu, pref, 2dlu, pref");

    layout.setRowGroups(new int[][] { { 1, 3 } });

    final JDialog dialog = new JDialog(frame, "Create Splinter Robot", true);
    dialog.setLayout(layout);
    final JTextField name = new JTextField();
    final JTextField x = new JTextField(Double.toString((pose.getX())));
    final JTextField y = new JTextField(Double.toString((pose.getY())));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(name, cc.xyw(3, 1, 5));
    dialog.add(new JLabel("x"), cc.xy(1, 3));
    dialog.add(x, cc.xy(3, 3));
    dialog.add(new JLabel("y"), cc.xy(5, 3));
    dialog.add(y, cc.xy(7, 3));
    dialog.add(cancel, cc.xyw(1, 5, 3));
    dialog.add(ok, cc.xyw(5, 5, 3));

    x.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setX(Double.parseDouble(x.getText()));
            } catch (NumberFormatException ex) {
                x.setText(Double.toString(pose.getX()));
            }
        }
    });

    y.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setY(Double.parseDouble(y.getText()));
            } catch (NumberFormatException ex) {
                y.setText(Double.toString(pose.getX()));
            }
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = name.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Create splinter: robot name empty");
                return;
            }
            for (char c : robotName.toCharArray())
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create splinter: illegal robot name");
                    return;
                }

            controller.createSplinterRobot(robotName, pose, true);
            controller.createSimSplinter(robotName);
            controller.createSimLaser(robotName);
            dialog.dispose();
        }
    };
    name.addActionListener(okListener);
    x.addActionListener(okListener);
    y.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.setLocationRelativeTo(frame);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java

private static JButton createBrowseButton(final boolean directoriesOnly, final String browserApproveButtonText,
        final JTextField textField, final FileFilter... fileFilters) {
    JButton browseButton = new JButton("...");
    browseButton.addActionListener(new ActionListener() {

        @Override// w ww.j a  v  a  2s .  c  om
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();

            if (textField.getText() != null) {
                File file = new File(textField.getText());

                // if the file doesn't exist but the directory does, get that
                if (!file.exists() && file.getParentFile() != null && file.getParentFile().exists()) {
                    file = file.getParentFile();
                }

                if (!directoriesOnly && file.isFile()) {
                    chooser.setSelectedFile(file);
                }

                if (file.isDirectory() && file.exists()) {
                    chooser.setCurrentDirectory(file);
                }
            }

            if (directoriesOnly) {
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            }

            // add filters and automatically select correct one
            if (fileFilters.length == 1) {
                chooser.setFileFilter(fileFilters[0]);
            } else {
                for (FileFilter filter : fileFilters) {
                    chooser.addChoosableFileFilter(filter);
                    if (filter instanceof FileNameExtensionFilter) {
                        if (matchesFilter((FileNameExtensionFilter) filter, textField.getText())) {
                            chooser.setFileFilter(filter);
                        }
                    }
                }
            }

            if (chooser.showDialog(textField, browserApproveButtonText) == JFileChooser.APPROVE_OPTION) {
                //File selected = processSelectedFile(chooser.getSelectedFile());
                File selected = chooser.getSelectedFile();

                String path = selected.getPath();
                FileFilter filter = chooser.getFileFilter();
                if (filter != null && filter instanceof FileNameExtensionFilter) {

                    boolean found = matchesFilter(((FileNameExtensionFilter) chooser.getFileFilter()), path);

                    if (!found) {
                        String[] exts = ((FileNameExtensionFilter) chooser.getFileFilter()).getExtensions();
                        if (exts.length > 0) {
                            path = FilenameUtils.removeExtension(path);
                            path += "." + exts[0];
                        }
                    }

                }
                textField.setText(path);
            }
        }
    });

    return browseButton;
}