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:com.ejie.uda.jsonI18nEditor.Editor.java

private void setupUI() {
    setTitle(TITLE);//from   ww w . j  a va  2  s  .  c om
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new EditorWindowListener());

    setIconImages(Lists.newArrayList(getResourceImage("images/icon-512.png"),
            getResourceImage("images/icon-256.png"), getResourceImage("images/icon-128.png"),
            getResourceImage("images/icon-64.png"), getResourceImage("images/icon-48.png"),
            getResourceImage("images/icon-32.png"), getResourceImage("images/icon-24.png"),
            getResourceImage("images/icon-20.png"), getResourceImage("images/icon-16.png")));

    translationsPanel = new JPanel(new BorderLayout());
    translationTree = new TranslationTree(this);
    translationTree.addTreeSelectionListener(new TranslationTreeNodeSelectionListener());
    translationField = new TranslationField();
    translationField.addKeyListener(new TranslationFieldKeyListener());
    translationsPanel.add(new JScrollPane(translationTree));
    translationsPanel.add(translationField, BorderLayout.SOUTH);

    resourcesPanel = new JScrollablePanel(true, false);
    resourcesPanel.setLayout(new BoxLayout(resourcesPanel, BoxLayout.Y_AXIS));
    resourcesPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    resourcesScrollPane = new JScrollPane(resourcesPanel);
    resourcesScrollPane.getViewport().setOpaque(false);

    contentPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, translationsPanel, resourcesScrollPane);
    editorMenu = new EditorMenu(this, translationTree);

    Container container = getContentPane();
    container.add(editorMenu, BorderLayout.NORTH);
    container.add(contentPane);

    // Instead of selecting text in text field when applying focus, set caret position to end of input
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("permanentFocusOwner",
            e -> {
                if (e.getNewValue() instanceof JTextField) {
                    JTextField field = (JTextField) e.getNewValue();
                    field.setCaretPosition(field.getText().length());
                }
            });
}

From source file:com.smanempat.controller.ControllerClassification.java

public String[] processMining(JTextField textNumberOfK, JTable tablePreview, JLabel labelPesanError,
        JTable tableResult, JLabel labelSiswaIPA, JLabel labelSiswaIPS, JLabel labelKeterangan,
        JYearChooser jYearChooser1, JYearChooser jYearChooser2, JTabbedPane jTabbedPane1) {

    String numberValidate = textNumberOfK.getText();
    ModelClassification modelClassification = new ModelClassification();
    int rowCountModel = modelClassification.getRowCount();
    int rowCountData = tablePreview.getRowCount();
    System.out.println("Row Count Data : " + rowCountData);
    System.out.println("Row Count Model : " + rowCountModel);
    String[] knnValue = null;/*from ww w. j  a  v  a 2 s  . c om*/

    /*Validasi Nilai Number of Nearest Neighbor*/
    if (Pattern.matches("[0-9]+", numberValidate) == false && numberValidate.length() > 0) {
        labelPesanError.setText("Number of Nearest Neighbor tidak valid");
        JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak valid!", "Error",
                JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png"));
        textNumberOfK.requestFocus();
    } else if (numberValidate.isEmpty()) {
        JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak boleh kosong!", "Error",
                JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png"));
        labelPesanError.setText("Number of Nearest Neighbor tidak boleh kosong");
        textNumberOfK.requestFocus();
    } else if (Integer.parseInt(numberValidate) >= rowCountModel) {
        labelPesanError.setText("Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + "");
        JOptionPane.showMessageDialog(null,
                "Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + " !", "Error",
                JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png"));
        textNumberOfK.requestFocus();
    } else {
        int confirm = 0;
        confirm = JOptionPane.showOptionDialog(null, "Yakin ingin memproses data?", "Proses Klasifikasi",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == JOptionPane.OK_OPTION) {
            int kValue = Integer.parseInt(textNumberOfK.getText());
            String[][] modelValue = getModelValue(rowCountModel);
            double[][] dataValue = getDataValue(rowCountData, tablePreview);
            knnValue = getKNNValue(rowCountData, rowCountModel, modelValue, dataValue, kValue);
            showClassificationResult(tableResult, tablePreview, knnValue, rowCountData, labelSiswaIPA,
                    labelSiswaIPS, labelKeterangan, jYearChooser1, jYearChooser2, kValue);
            jTabbedPane1.setSelectedIndex(1);
        }

    }
    return knnValue;
}

From source file:de.wusel.partyplayer.gui.PartyPlayer.java

private JComponent createMainComponent() {
    JPanel mainPanel = new JPanel(new MigLayout("fill", "[][50%][][50%]", "[] [] [] [] [grow]"));
    mainPanel.add(new JLabel(getText("layout.current.title")));
    mainPanel.add(new JSeparator(), "growx");
    mainPanel.add(new JLabel(getText("layout.next.title")));
    mainPanel.add(new JSeparator(), "growx, wrap");
    mainPanel.add(createPlayerPanel(), "grow, span 2");
    mainPanel.add(createPlayListPanel(), "grow, hmax 100, span 2, wrap");
    mainPanel.add(new JLabel(getText("layout.available.title")));
    mainPanel.add(new JSeparator(), "growx, span, wrap");
    final JTextField searchField = new JTextField();
    searchField.addKeyListener(new KeyAdapter() {

        @Override//from   ww  w  .  j a  v  a  2 s .c o  m
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                searchField.setText(null);
                table.setRowFilter(null);
            }
            try {
                table.setRowFilter(
                        RowFilter.regexFilter("(?i)" + Pattern.quote(searchField.getText()), 0, 1, 3));
            } catch (PatternSyntaxException ex) {
                table.setRowFilter(null);
                //do nothing
            }
        }
    });
    mainPanel.add(new JLabel(getText("layout.search.label")));
    mainPanel.add(searchField, "span, growx, wrap");
    mainPanel.add(createSongPanel(), "span, grow");
    return mainPanel;
}

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

private int getInteger(JTextField tf) {
    final String val = tf.getText();
    try {//from   w  ww  .j a va  2 s  .c  om
        if (StringUtils.isNotBlank(val)) {
            return Integer.parseInt(val.trim());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:com.intuit.tank.proxy.ProxyApp.java

private JPanel getTransactionTable() {
    JPanel frame = new JPanel(new BorderLayout());
    model = new TransactionTableModel();
    final JTable table = new TransactionTable(model);
    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);//from   w w w  .  jav  a  2  s  .c  o  m
    final JPopupMenu pm = new JPopupMenu();
    JMenuItem item = new JMenuItem("Delete Selected");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int[] selectedRows = table.getSelectedRows();
            if (selectedRows.length != 0) {
                int response = JOptionPane.showConfirmDialog(ProxyApp.this,
                        "Are you sure you want to delete " + selectedRows.length + " Transactions?",
                        "Confirm Delete", JOptionPane.YES_NO_OPTION);
                if (response == JOptionPane.YES_OPTION) {
                    int[] correctedRows = new int[selectedRows.length];
                    for (int i = selectedRows.length; --i >= 0;) {
                        int row = selectedRows[i];
                        int index = (Integer) table.getValueAt(row, 0) - 1;
                        correctedRows[i] = index;
                    }
                    Arrays.sort(correctedRows);
                    for (int i = correctedRows.length; --i >= 0;) {
                        int row = correctedRows[i];
                        Transaction transaction = model.getTransactionForIndex(row);
                        if (transaction != null) {
                            model.removeTransaction(transaction, row);
                            isDirty = true;
                            saveAction.setEnabled(isDirty && !stopAction.isEnabled());
                        }
                    }
                }
            }
        }
    });
    pm.add(item);
    table.add(pm);

    table.addMouseListener(new MouseAdapter() {
        boolean pressed = false;

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                Point p = e.getPoint();
                int row = table.rowAtPoint(p);
                int index = (Integer) table.getValueAt(row, 0) - 1;
                Transaction transaction = model.getTransactionForIndex(index);
                if (transaction != null) {
                    detailsTF.setText(transaction.toString());
                    detailsTF.setCaretPosition(0);
                    detailsDialog.setVisible(true);
                }
            }
        }

        /**
         * @{inheritDoc
         */
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                pressed = true;
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows.length != 0) {
                    pm.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }

        /**
         * @{inheritDoc
         */
        @Override
        public void mouseReleased(MouseEvent e) {
            if (!pressed && e.isPopupTrigger()) {
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows.length != 0) {
                    pm.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }

    });

    JScrollPane pane = new JScrollPane(table);
    frame.add(pane, BorderLayout.CENTER);
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Filter: ");
    panel.add(label, BorderLayout.WEST);
    final JLabel countLabel = new JLabel(" Count: 0 ");
    panel.add(countLabel, BorderLayout.EAST);
    final JTextField filterText = new JTextField("");
    filterText.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            String text = filterText.getText();
            if (text.length() == 0) {
                sorter.setRowFilter(null);
            } else {
                try {
                    sorter.setRowFilter(RowFilter.regexFilter(text));
                    countLabel.setText(" Count: " + sorter.getViewRowCount() + " ");
                } catch (PatternSyntaxException pse) {
                    System.err.println("Bad regex pattern");
                }
            }
        }
    });
    panel.add(filterText, BorderLayout.CENTER);

    frame.add(panel, BorderLayout.NORTH);
    return frame;
}

From source file:com.vrane.metaGlacier.gui.MetaDataSignUpDialog.java

MetaDataSignUpDialog() {
    super(Main.frame, true);
    JPanel signUpPanel = new JPanel(new GridLayout(4, 2));
    final JTextField nameJT = new JTextField(10);
    final JTextField emailJT = new JTextField(10);
    final JTextField emailJT1 = new JTextField(10);
    final JButton signUpButton = new JButton("Sign up");

    signUpPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5));

    signUpPanel.add(new JLabel("name (optional)"));
    signUpPanel.add(nameJT);//  w ww .ja v  a2s . c  o  m

    signUpPanel.add(new JLabel("email"));
    signUpPanel.add(emailJT);

    signUpPanel.add(new JLabel("email again"));
    signUpPanel.add(emailJT1);

    signUpPanel.add(new JLabel());

    signUpPanel.add(signUpButton);
    signUpButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            final String email = emailJT.getText();
            final String email1 = emailJT1.getText();
            final String name = nameJT.getText();
            boolean success = false;

            if (!email.equals(email1)) {
                JOptionPane.showMessageDialog(null, "Email addresses do not match");
                return;
            }
            if (!EmailValidator.getInstance().isValid(email)) {
                JOptionPane.showMessageDialog(null, "Invalid email address");
                return;
            }
            try {
                success = new SignUp().signup(email, name);
            } catch (SDKException ex) {
                LGR.log(Level.SEVERE, null, ex);
            }
            if (success) {
                JOptionPane.showMessageDialog(null, "Please check your email to confirm");
                dispose();
                return;
            }
            JOptionPane.showMessageDialog(null, "Error signing up");
        }
    });
    add(signUpPanel);
    pack();
    setLocationRelativeTo(Main.frame);
    setVisible(true);
}

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

protected void handleSearchInput() {
    JTextField searchEditor = getComboBoxEditorField();
    String currentSearchString = StringUtils.trimToEmpty(searchEditor.getText());
    if (!Objects.equals(currentSearchString, lastSearchString)) {
        lastSearchString = currentSearchString;

        if (searchExecutor != null) {
            if (asyncSearchWorker != null) {
                log.debug("Cancel previous search");

                asyncSearchWorker.cancel(true);
            }//from   w  ww  .  j  a  va 2 s.  c  om

            if (currentSearchString.length() >= minSearchStringLength) {
                Map<String, Object> params = null;
                if (searchExecutor instanceof ParametrizedSearchExecutor) {
                    //noinspection unchecked
                    params = ((ParametrizedSearchExecutor) searchExecutor).getParams();
                }
                asyncSearchWorker = createSearchWorker(currentSearchString, params);
                asyncSearchWorker.execute();
            }
        }
    }
}

From source file:com.vrane.metaGlacier.gui.SNSTopicDialog.java

SNSTopicDialog() {
    super(Main.frame, true);
    JPanel mainPanel = new JPanel(new GridLayout(4, 2));
    final JTextField topicNameJT = new JTextField(10);
    final JTextField emailJT = new JTextField(10);
    final JButton subscribeButton = new JButton("subscribe");

    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5));

    mainPanel.add(new JLabel("topic name"));
    mainPanel.add(topicNameJT);//from  w  ww .j a v  a 2s  . co  m

    mainPanel.add(new JLabel("email"));
    mainPanel.add(emailJT);

    final String metadata_account_email = Main.frame.getMPCUser();
    if (metadata_account_email != null) {
        emailJT.setText(metadata_account_email);
    }

    mainPanel.add(new JLabel());
    mainPanel.add(subscribeButton);
    subscribeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            final String email = emailJT.getText();
            final String name = topicNameJT.getText();
            boolean success = false;

            if (!EmailValidator.getInstance().isValid(email)) {
                JOptionPane.showMessageDialog(null, "Invalid email address");
                return;
            }
            try {
                success = new SNSTopic().createTopic(name, email);
            } catch (Exception ex) {
                LGR.log(Level.SEVERE, null, ex);
            }
            if (success) {
                JOptionPane.showMessageDialog(null, "Please check your email to confirm");
                dispose();
                return;
            }
            JOptionPane.showMessageDialog(null, "Error subscribing");
        }
    });
    add(mainPanel);
    pack();
    setLocationRelativeTo(Main.frame);
    setVisible(true);
}

From source file:main.UIController.java

/************* TO GREGORIAN *************/

public void updateDayComboImladris() {
    UI window = this.getUi();

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JButton convert = window.getToGregorian();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {// ww  w  . ja va2  s . co  m
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    day.setEnabled(false);
                    day.setModel(new DefaultComboBoxModel());
                    convert.setEnabled(true);
                    result.setText("");
                } else {
                    int daySel = 0;
                    if (day.isEnabled()) {
                        daySel = day.getSelectedIndex() + 1;
                    }
                    ArrayList<Integer> days = ImladrisInfo.getInstance().getDaysArray(yenNum, loaNum,
                            periodNum);
                    day.setModel(new DefaultComboBoxModel(days.toArray()));
                    if (daySel > 0 && daySel <= days.size()) {
                        day.setSelectedIndex(daySel - 1);
                    }
                    day.setEnabled(true);
                    convert.setEnabled(true);
                    result.setText("");
                }
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}

From source file:edu.ku.brc.specify.ui.DBObjSearchPanel.java

/**
 * @param comp/*from   w w w .  j  a  v a 2s .  c o  m*/
 */
protected void doStartQuery(final JComponent comp) {
    getDataFromUI();

    QueryForIdResultsIFace resultsInfo = null;
    if (queryBuilder != null) {
        sqlStr = queryBuilder.buildSQL(dataMap, fieldNames);
        if (StringUtils.isNotEmpty(sqlStr)) {
            resultsInfo = queryBuilder.createQueryForIdResults();
            if (resultsInfo != null) {
                resultsInfo.setSQL(sqlStr);
                resultsInfo.setMultipleSelection(isMultipleSelection);
            }

        } else {
            UIRegistry.getStatusBar().setLocalizedErrorMessage("ES_SUSPICIOUS_SQL");
            return;
        }

    } else {
        QueryAdjusterForDomain qafd = QueryAdjusterForDomain.getInstance();
        StringBuilder strBuf = new StringBuilder(256);
        int cnt = 0;
        for (ERTICaptionInfo captionInfo : esTableInfo.getVisibleCaptionInfo()) {
            String colName = null;

            Object value = null;
            if (captionInfo.getColName() == null) {
                for (ColInfo colInfo : captionInfo.getColInfoList()) {
                    colName = colInfo.getColumnName();
                    log.debug("colInfo - colInfoColumn Name[" + colName + "]");

                    value = dataMap.get(colName);
                    if (value != null) {
                        log.debug("Column Name[" + colName + "][" + captionInfo.getColLabel() + "] ["
                                + captionInfo.getFieldInfo() + "] Value[" + value + "]");
                        break;
                    }
                }
            } else {
                colName = captionInfo.getColName();
                value = StringUtils.isNotEmpty(colName) ? dataMap.get(captionInfo.getColName()) : null;
                log.debug("Column Name[" + colName + "][" + captionInfo.getColLabel() + "] ["
                        + captionInfo.getFieldInfo() + "] Value[" + value + "]");
            }

            if (value != null) {
                String valStr = value.toString();
                if (valStr.length() > 0) {
                    if (qafd.isUserInputNotInjectable(valStr)) {
                        if (ESTermParser.getInstance().parse(valStr.toLowerCase(), true)) {
                            if (StringUtils.isNotEmpty(valStr)) {
                                List<SearchTermField> fields = ESTermParser.getInstance().getFields();
                                SearchTermField firstTerm = fields.get(0);

                                if (cnt > 0) {
                                    strBuf.append(" AND ");
                                }

                                String clause = null;

                                if (captionInfo.getFieldInfo() != null && form instanceof FormViewObj) {
                                    FormViewObj fvo = (FormViewObj) form;
                                    FormViewObj.FVOFieldInfo fInfo = fvo.getFieldInfoForName(colName);
                                    if (fInfo != null) {
                                        if (fInfo.getFormCell() != null && fInfo.getFormCell()
                                                .getPropertyAsBoolean("ispartial", false)) {
                                            if (fInfo.getFormCell() instanceof FormCellFieldIFace) {
                                                FormCellFieldIFace cif = (FormCellFieldIFace) fInfo
                                                        .getFormCell();
                                                String fmt = cif.getUIFieldFormatterName();
                                                if (StringUtils.isNotEmpty(fmt) && fmt.equals("SearchDate")) // XXX There is a better way to check for this (use the enum)
                                                {
                                                    clause = getDateClause(firstTerm, colName);
                                                }
                                            }
                                            if (clause == null) {
                                                firstTerm.setTerm(firstTerm.getTermLowerCase());
                                                firstTerm.setOption(SearchTermField.ENDS_WILDCARD);
                                            }
                                        }
                                    }
                                }

                                if (clause == null) {
                                    clause = ESTermParser.getInstance().createWhereClause(firstTerm, null,
                                            colName);
                                }
                                strBuf.append(clause);
                                cnt++;
                            }
                        }
                    } else {
                        UIRegistry.getStatusBar().setErrorMessage(getResourceString("ES_SUSPICIOUS_SQL"));
                        return;
                    }
                }
            } /* else
              {
              log.debug("DataMap was null for Column Name["+captionInfo.getColName()+"] make sure there is a field of this name in the form.");
              }*/
        }

        if (cnt == 0) {
            return;
        }

        String fullStrSql = QueryAdjusterForDomain.getInstance().adjustSQL(sqlStr);
        String fullSQL = fullStrSql.replace("%s", strBuf.toString());
        log.info(fullSQL);
        setUIEnabled(false);

        resultsInfo = new QueryForIdResultsSQL(esTableInfo.getId(), null, esTableInfo, 0, "");
        resultsInfo.setSQL(fullSQL);
        resultsInfo.setMultipleSelection(isMultipleSelection);
    }

    addSearchResults(resultsInfo);

    if (comp instanceof JTextField) {
        final JTextField txt = (JTextField) comp;
        int len = txt.getText().length();
        txt.setSelectionEnd(len);
        txt.setSelectionStart(0);

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                txt.requestFocus();
            }
        });
    }
}