Example usage for javax.swing JTextField getText

List of usage examples for javax.swing JTextField getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent.

Usage

From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

public File fileChooser(JTextField jtf, String ext, String openOrSave) {
    jfcFiles = new JFileChooser(jtf.getText());
    if (!ext.equals(""))
        jfcFiles.addChoosableFileFilter(new MyFileFilter(ext));
    jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    int state;//from w  w  w .  j a va2s  .  c  om
    if (openOrSave.equals("open"))
        state = jfcFiles.showOpenDialog(null);
    else
        state = jfcFiles.showSaveDialog(null);

    if (state == JFileChooser.APPROVE_OPTION) {
        File file = checkFileExtension(ext);
        jtf.setText(file.getPath());
        log.info("Opening: " + file.getName() + ".");
        return file;
    } else {
        log.info("Open command cancelled by user.");
        return null;
    }
}

From source file:kenh.xscript.elements.Debug.java

private void parse(JTextField c) {
    if (result == null)
        return;/*w  ww . j  a  va 2s.co m*/

    if (StringUtils.isBlank(c.getText()))
        return;

    if (this.getEnvironment() != null) {
        String context = "";
        try {
            Object obj = this.getEnvironment().parse(c.getText());
            context = (obj != null
                    ? obj.toString() + LINE_SEP + LINE_SEP + "-- Class: " + obj.getClass().getCanonicalName()
                    : "<null>");

        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            context = sw.toString();
        }

        result.setText(context);

    } else {
        result.setText(c.getText());
    }

    result.setCaretPosition(0);
    c.requestFocus();
}

From source file:cz.alej.michalik.totp.client.AddDialog.java

/**
 * Naformtuje sdlen heslo// www.ja va 2  s. c  o m
 * 
 * @param secret
 *            textov pole se sdlenm heslem
 * @return
 */
private void sanitize(final JTextField secret) {
    // Velk psmena a odstrann mezer
    String text = secret.getText().toUpperCase().trim().replaceAll(" ", "");
    secret.setText(text);
}

From source file:biomine.bmvis2.pipeline.TextFilterShower.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    final JTextField filterField = new JTextField();
    ret.add(filterField);/*  w w  w  .ja v a2  s  . co m*/
    filterField.getDocument().addDocumentListener(new DocumentListener() {
        private void update() {
            if (filterField.getText().equals(""))
                return;
            if (filterField.getText().equals(TextFilterShower.this.filter))
                return;
            TextFilterShower.this.filter = filterField.getText();
            v.settingsChanged(false);
        }

        public void insertUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void removeUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void changedUpdate(DocumentEvent documentEvent) {
            this.update();
        }
    });

    return ret;
}

From source file:biomine.bmvis2.pipeline.TextFilterHider.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    final JTextField filterField = new JTextField();
    ret.add(filterField);//from   w  ww.j  a v a 2 s  .  c om
    filterField.getDocument().addDocumentListener(new DocumentListener() {
        private void update() {
            if (filterField.getText().equals(""))
                return;
            if (filterField.getText().equals(TextFilterHider.this.filter))
                return;
            TextFilterHider.this.filter = filterField.getText();
            v.settingsChanged(false);
        }

        public void insertUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void removeUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void changedUpdate(DocumentEvent documentEvent) {
            this.update();
        }
    });

    return ret;
}

From source file:com.github.cric.app.ui.SettingPanel.java

private boolean validateText(JTextField f) {

    if (f.getText().length() <= 0) {
        return false;
    }/*w  ww.  j  ava  2 s .c  o  m*/
    return true;
}

From source file:Listeners.MyActionListener.java

public boolean validateAddAction(JTextField name) {
    if (name.getText().equals(""))
        return false;
    return true;/*from  w  ww .j av  a 2  s . com*/
}

From source file:Listeners.MyActionListener.java

public boolean validateEditAction(JTextField name) {
    if (name.getText().equals(""))
        return false;
    return true;/*from ww w . java 2 s .c o m*/
}

From source file:TextSamplerDemo.java

public void actionPerformed(ActionEvent e) {
    String prefix = "You typed \"";
    if (textFieldString.equals(e.getActionCommand())) {
        JTextField source = (JTextField) e.getSource();
        actionLabel.setText(prefix + source.getText() + "\"");
    } else if (passwordFieldString.equals(e.getActionCommand())) {
        JPasswordField source = (JPasswordField) e.getSource();
        actionLabel.setText(prefix + new String(source.getPassword()) + "\"");
    } else if (buttonString.equals(e.getActionCommand())) {
        Toolkit.getDefaultToolkit().beep();
    }/*from  www. j av  a 2s .c o m*/
}

From source file:cool.pandora.modeller.ui.jpanel.base.BagInfoForm.java

/**
 * getBagInfoMap./* w  ww .j  av  a2  s .c o m*/
 *
 * @return map
 */
public HashMap<String, String> getBagInfoMap() {
    final HashMap<String, String> map = new HashMap<>();
    String key = "";
    String value = "";
    final Component[] components = getFieldComponents();
    for (int i = 0; i < components.length; i++) {
        Component c;
        c = components[i];
        if (c instanceof JLabel) {
            final JLabel label = (JLabel) c;
            key = label.getText();
        }
        i++;
        // Is required component
        c = components[i];
        i++;
        c = components[i];
        if (c instanceof JTextField) {
            final JTextField tf = (JTextField) c;
            value = tf.getText();
        } else if (c instanceof JTextArea) {
            final JTextArea ta = (JTextArea) c;
            value = ta.getText();
        } else if (c instanceof JComboBox) {
            final JComboBox<?> tb = (JComboBox<?>) c;
            value = (String) tb.getSelectedItem();
        }
        map.put(key, value);
        i++;
        c = components[i];
    }
    return map;
}