List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. From source file:com.bsb.intellij.plugins.xmlbeans.facet.ui.validation.ValidRelativePathValidator.java
@Nullable @Override/*w ww. j a va2 s. c o m*/ public String getErrorMessage(JTextField field, JBLabel label) { String text = field.getText(); String errorMessage = null; if (SwingUtils.isVisible(field) && StringUtils.isNotBlank(text) && !ValidationUtils.isValidRelativePath(text)) { errorMessage = label.getText() + " should be a valid relative path."; } return errorMessage; }
From source file:Main.java
Main() { JPanel p = new JPanel(new BorderLayout(2, 2)); JTextField find = new JTextField("food:pizza"); find.addActionListener(e -> {/*from w ww.j av a 2 s .c o m*/ boolean found = findText(find.getText()); System.out.println(find.getText() + " found " + found); }); p.add(find, BorderLayout.PAGE_START); tree.setVisibleRowCount(8); for (int row = tree.getRowCount(); row >= 0; row--) { tree.expandRow(row); } p.add(new JScrollPane(tree), BorderLayout.CENTER); JOptionPane.showMessageDialog(null, p); }
From source file:com.bsb.intellij.plugins.xmlbeans.facet.ui.validation.MandatoryFieldValidator.java
@Nullable @Override//from w ww . j a v a 2 s . co m public String getErrorMessage(JTextField field, JBLabel label) { String errorMessage = null; if (SwingUtils.isVisible(field) && StringUtils.isBlank(field.getText())) { errorMessage = label.getText() + " is mandatory."; } return errorMessage; }
From source file:edu.ku.brc.specify.config.init.DivisionPanel.java
@Override public boolean isUIValid() { if (super.isUIValid()) { JTextField tf = (JTextField) comps.get("divName"); if (tf != null) { String name = tf.getText(); if (DBConnection.getInstance().getConnection() != null && StringUtils.isNotEmpty(name)) { int cnt = BasicSQLUtils .getCountAsInt(String.format("SELECT COUNT(*) FROM division WHERE Name = '%s'", name)); if (cnt > 0) { UIRegistry.showLocalizedError("DIVNAME_DUP", name); return false; }/* w ww. ja va2 s. c om*/ return true; } } } return false; }
From source file:edu.ku.brc.specify.config.init.CollectionPanel.java
@Override public boolean isUIValid() { if (super.isUIValid()) { JTextField tf = (JTextField) comps.get("collName"); if (tf != null) { String name = tf.getText(); if (DBConnection.getInstance().getConnection() != null && StringUtils.isNotEmpty(name)) { int cnt = BasicSQLUtils.getCountAsInt( String.format("SELECT COUNT(*) FROM collection WHERE CollectionName = '%s'", name)); if (cnt > 0) { UIRegistry.showLocalizedError("COLLNAME_DUP", name); return false; }/* w ww . j a va 2 s . com*/ return true; } } } return false; }
From source file:edu.ku.brc.specify.config.init.NewAgentPanel.java
/** * Checks all the textfields to see if they have text * @return true of all fields have text//from ww w . jav a 2 s. co m */ public boolean isUIValid() { JTextField[] txtFields = { firstNameTxt, lastNameTxt, emailTxt }; for (JTextField tf : txtFields) { if (StringUtils.isEmpty(tf.getText())) { return false; } } return true; }
From source file:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);//from w w w . j a v a 2 s . c o m JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:de.codesourcery.eve.skills.ui.components.impl.PriceInfoComponent.java
protected double getValue(JTextField input) throws NumberFormatException { final String value = input.getText(); if (StringUtils.isBlank(value)) { throw new NumberFormatException("You need to enter a positive number"); }// w ww. j av a2 s .co m final double val = Double.parseDouble(value); if (val < 0) { throw new NumberFormatException("You need to enter a positive number"); } return val; }
From source file:ToolBarDemo2.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); String description = null;// ww w .java 2 s . c o m // Handle each button. if (PREVIOUS.equals(cmd)) { //first button clicked description = "taken you to the previous <something>."; } else if (UP.equals(cmd)) { // second button clicked description = "taken you up one level to <something>."; } else if (NEXT.equals(cmd)) { // third button clicked description = "taken you to the next <something>."; } else if (SOMETHING_ELSE.equals(cmd)) { // fourth button clicked description = "done something else."; } else if (TEXT_ENTERED.equals(cmd)) { // text field JTextField tf = (JTextField) e.getSource(); String text = tf.getText(); tf.setText(""); description = "done something with this text: " + newline + " \"" + text + "\""; } displayResult("If this were a real app, it would have " + description); }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/*from w ww .j a va 2 s .com*/ JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); // Setting the Slider sets that font into the textfield. stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }