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:ViewDB.java

 /**
 * Updates changed data into the current row of the row set
 *///from  w  w w .  java2s . c om
public void setRow(RowSet rs) throws SQLException
{
   for (int i = 1; i <= fields.size(); i++)
   {
      String field = rs.getString(i);
      JTextField tb = (JTextField) fields.get(i - 1);
      if (!field.equals(tb.getText()))
         rs.updateString(i, tb.getText());
   }
   rs.updateRow();
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopFilterHelper.java

@Override
public void addTextChangeListener(TextField textField, final TextChangeListener listener) {
    final JTextField dTextField = (JTextField) DesktopComponentsHelper.unwrap(textField);
    dTextField.addKeyListener(new KeyAdapter() {
        @Override/* w  w w . j av  a 2  s  . c om*/
        public void keyReleased(KeyEvent e) {
            listener.textChanged(dTextField.getText());
        }
    });
}

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

private boolean validateInt(JTextField f) {

    try {/*w  w  w. j  a v  a2 s . co m*/
        int i = Integer.parseInt(f.getText());
        if (i <= 0) {

            return false;
        }
        return true;
    } catch (NumberFormatException e) {
        return false;
    }
}

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

/**
 * Odele nov zznam/*from ww w . j av a 2s  . co  m*/
 * 
 * @param prop
 *            Properties
 * @param name
 *            Textov pole s jmnem
 * @param secret
 *            Textov pole s heslem
 * @param exitOnError
 *            Zave okno i pi chyb, pokud uivatel klikne na kek
 */
private void submit(final Properties prop, final JTextField name, final JTextField secret,
        boolean exitOnError) {
    System.out.printf("Jmno: %s | Heslo: %s\n", name.getText(), secret.getText());
    boolean error = false;
    sanitize(secret);
    if (name.getText().equals("") || secret.getText().equals("") || !verify(secret)) {
        System.out.println("Nepidno");
        error = true;
    } else {
        System.out.printf("Base32 heslo je: %s\n", new Base32().encodeToString(secret.getText().getBytes()));
        int id = prop.size();
        // Po odstrann me bt nkter index pesko?en
        while (prop.containsKey(String.valueOf(id))) {
            id++;
        }
        StringBuilder sb = new StringBuilder();
        // Zznam je ve tvaru "jmno;heslo"
        sb.append(name.getText());
        sb.append(";");
        sb.append(secret.getText());
        prop.setProperty(String.valueOf(id), sb.toString());
        App.saveProperties();
        App.loadProperties();
    }
    if (exitOnError || !error) {
        this.dispose();
    }
}

From source file:LDAPTest.java

public Attributes getEditedAttributes() {
        Attributes attrs = new BasicAttributes();
        for (int i = 0; i < getComponentCount(); i += 2) {
            JLabel idLabel = (JLabel) getComponent(i);
            JTextField valueField = (JTextField) getComponent(i + 1);
            String id = idLabel.getText();
            String value = valueField.getText();
            if (id.equals("userPassword"))
                attrs.put("userPassword", value.getBytes());
            else if (!id.equals("") && !id.equals("objectClass"))
                attrs.put(id, value);//from ww w .  j  av  a 2s.  c  o m
        }
        return attrs;
    }

From source file:de.mycrobase.jcloudapp.Main.java

private static Map<String, String> showLoginDialog() {
    String message = ""; //"Welcome to JCloudApp!";

    JTextField usernameField = new JTextField();
    JPasswordField passwordField = new JPasswordField();
    JCheckBox remeberCheck = new JCheckBox("Remember login (on disk)");
    remeberCheck.setSelected(true);/*from  w ww .  j  a v a  2 s .c om*/
    Object[] content = { message, "Username:", usernameField, "Password:", passwordField, remeberCheck };

    //        int res = JOptionPane.showOptionDialog(
    //            null, content, "JCloudApp - Login",
    //            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon,
    //            null, usernameField);
    int res = JOptionPane.showConfirmDialog(null, content, "JCloudApp - Login", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, IconLarge);

    if (res == JOptionPane.OK_OPTION) {
        HashMap<String, String> m = new HashMap<String, String>();
        m.put("username", usernameField.getText());
        m.put("password", new String(passwordField.getPassword()));
        m.put("remember", Boolean.toString(remeberCheck.isSelected()));
        return m;
    } else {
        return null;
    }
}

From source file:fr.free.hd.servers.gui.PhonemView.java

@Override
protected JComponent createControl() {
    final JPanel view = new JPanel(new BorderLayout());

    Collection<Phonem> phonesList = phonemsDAO.getPhonems();
    Map<String, Phonem> mapList = new HashMap<String, Phonem>();
    for (Phonem phonem : phonesList) {
        mapList.put(phonem.getPhonem(), phonem);
    }/*from   w  w  w  .  ja v  a 2  s  . com*/

    final StatementListModel model = new StatementListModel(mapList);

    printCommand.setModel(model);
    printCommand.setFace(face);
    copyCommand.setModel(model);
    copyCommand.setFace(face);

    list = new JList(model);
    final JScrollPane sp = new JScrollPane(list);
    final JTextField field = new JTextField();
    field.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

    });

    final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList);
    final JList phonemList = new JList(phonemModel);
    final JScrollPane spPhonemList = new JScrollPane(phonemList);
    phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        // private int oldIndex = -1;
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex());
                field.setText(field.getText() + innerPhonem.getPhonem());
            }
        }
    });
    phonemList.setCellRenderer(new PhonemListRenderer());
    list.setCellRenderer(new StatementPhonemListRenderer(face));
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(1);

    view.add(spPhonemList, BorderLayout.WEST);
    view.add(sp, BorderLayout.CENTER);
    view.add(field, BorderLayout.SOUTH);

    field.requestFocus();

    return view;
}

From source file:de.codesourcery.eve.skills.ui.components.impl.planning.CalendarEntryEditorComponent.java

private Duration toDuration(JTextField textField, JComboBox box) {
    final Duration.Type type = (Duration.Type) box.getSelectedItem();
    final long value = Long.parseLong(textField.getText());
    return new Duration(type.toSeconds() * value);
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static void setNumberInputVerifier(JTextField field) {
    // Add the input verifier
    field.setInputVerifier(new InputVerifier() {
        @Override/* w  w w. ja v a  2s. c  o m*/
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String txt = field.getText();
            if (txt.isEmpty()) {
                field.setToolTipText(UILabels.STL50084_CANT_BE_BLANK.getDescription());
                input.setBackground(UIConstants.INTEL_LIGHT_RED);
                return false;
            }
            try {
                Utils.toLong(txt);
                input.setBackground(UIConstants.INTEL_WHITE);
                return true;
            } catch (Exception e) {
                field.setToolTipText(UILabels.STL50085_MUST_BE_NUMERIC.getDescription());
                input.setBackground(UIConstants.INTEL_LIGHT_RED);
            }
            return false;
        }

    });
}

From source file:edu.ku.brc.specify.datamodel.busrules.AgentBusRules.java

/**
 * @param specifyUser/*from  w w  w  . j  av a  2 s.  c  om*/
 * @param division
 * @return
 */
public static boolean createUserAgent(final SpecifyUser specifyUser, final Division division) {
    final JTextField fName = UIHelper.createTextField(20);
    final JTextField lName = UIHelper.createTextField();
    final JTextField email = UIHelper.createTextField();

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px"));
    pb.add(UIHelper.createFormLabel("First Name"), cc.xy(1, 1));
    pb.add(UIHelper.createFormLabel("Last Name"), cc.xy(1, 3));
    pb.add(UIHelper.createFormLabel("Email"), cc.xy(1, 5));

    pb.add(fName, cc.xy(3, 1));
    pb.add(lName, cc.xy(3, 3));
    pb.add(email, cc.xy(3, 5));

    pb.setDefaultDialogBorder();
    CustomDialog dlg = new CustomDialog((Dialog) null, "Create Agent", true, CustomDialog.OKCANCEL,
            pb.getPanel());
    UIHelper.centerAndShow(dlg);

    boolean hasData = StringUtils.isNotEmpty(lName.getText()) && StringUtils.isNotEmpty(fName.getText());
    if (hasData && !dlg.isCancelled()) {
        Agent usrAgent = new Agent();
        usrAgent.initialize();

        DataProviderSessionIFace session = null;
        try {
            session = DataProviderFactory.getInstance().createSession();

            session.beginTransaction();
            SpecifyUser spUser = session.merge(specifyUser);
            usrAgent.setLastName(lName.getText());
            usrAgent.setFirstName(fName.getText());
            usrAgent.setEmail(email.getText());

            usrAgent.setSpecifyUser(spUser);
            spUser.getAgents().add(usrAgent);
            usrAgent.setDivision(division); // Set the new Division

            session.saveOrUpdate(usrAgent);
            session.saveOrUpdate(spUser);
            session.commit();

            return true;

        } catch (Exception ex) {
            if (session != null) {
                session.rollback();
            }
        } finally {
            if (session != null)
                session.close();
        }
    }
    return false;
}