javax.swing.JTextField.getName()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中javax.swing.JTextField.getName()方法的一些代码示例,展示了JTextField.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getName()方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getName

JTextField.getName介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

JTextField[] txtFieldA = new JTextField[13] ;
txtFieldFirstName.setName("First Name") ; //add name for all text fields
txtFieldA[0] = txtFieldFirstName ;
txtFieldA[1] = txtFieldLastName ;
....
// in action event
for(JTextField txtField : txtFieldA) {
 if(txtField.getText().equals("") ) {
  JOptionPane.showMessageDialog(null, txtField.getName() +" is empty!");
  //break it to avoid multiple popups
  break;
 }
}

代码示例来源:origin: stackoverflow.com

public void actionPerformed(ActionEvent e) {
   JTextField tf = (JTextField)e.getSource();
   myAction(tf, tf.getName());
 }

代码示例来源:origin: stackoverflow.com

JTextField tf = (JTextField) FrameUtils
         .getComponentById(
             instance.getContentPane(), "reg_r"
                 + i);
     Component c = (Component) getFocusOwner();
     if (c == null || !tf.getName().equals(c.getName())) {
     // JTextField is not focused/being edited, proceed with update
     tf.setText(...);
     }

代码示例来源:origin: stackoverflow.com

for (Component c : panel1.getComponents()) {
  if (c instanceof JTextField) { 
    JTextField textField = ((JTextField)c);
    String name;
    String contact;
    if(textField.getName().startsWith("Name") {
      // Name field
      name = textField.getText();
    } else {
      // Contact field
      contact = textField.getText();

    }
    // Validate and persist.
  }
}

代码示例来源:origin: net.java.abeille/abeille

public void focusLost(FocusEvent evt) {
    JTextField comp = (JTextField) evt.getSource();
    String old_value = (String) m_txt_values.get(comp);
    if (!comp.getText().equals(old_value)) {
      JETAController.this.actionPerformed(comp.getName(), new ActionEvent(comp, ActionEvent.ACTION_PERFORMED, comp.getName()));
    }
  }
}

代码示例来源:origin: stackoverflow.com

public String validate(JTextField... fields) {
  StringBuilder builder = new StringBuilder();
  for (JTextField s : fields) {
    if (s.getText() == null || "".equals(s.getText())) {
      builder.append(s.getName() + " is missing\n");
    }
  }
  return builder.toString();
}

private void addPersonButtonActionPerformed(java.awt.event.ActionEvent evt) {
  String message = validate(firstNameTextField,lastNameTextField,emailTextField);
  if(message.isEmpty()) // addperson...
  else // print message .. 
}

代码示例来源:origin: dboissier/jenkins-control-plugin

public void validate(JTextField component) throws ConfigurationException {
    if (component.isEnabled()) {    //TODO a revoir
      String value = component.getText();
      if (StringUtils.isEmpty(value)) {
        throw new ConfigurationException(String.format("'%s' must be set", component.getName()));
      }
    }
  }
}

代码示例来源:origin: org.fudaa.framework.ebli/ebli-3d

public void actionPerformed(final ActionEvent _e) {
  final JTextField texte = (JTextField) _e.getSource();
  try {
   if ((lock_.isSelected()) && (texte.getName().substring(0, 2).equals("ec"))) {
    firePropertyChange("echelleX", 0f, Float.parseFloat(texte.getText()));
    firePropertyChange("echelleY", 0f, Float.parseFloat(texte.getText()));
    firePropertyChange("echelleZ", 0f, Float.parseFloat(texte.getText()));
   } else {
    firePropertyChange(texte.getName(), 0f, Float.parseFloat(texte.getText()));
    // texte.setText("");
   }
  } catch (final NumberFormatException ex) {};
  texte.setText("");
 }
}

代码示例来源:origin: stackoverflow.com

public void someMethod() {
  JTextField tf1 = new JTextField(10);
  tf1.setName("tf1");
  JTextField tf2 = new JTextField(10);
  tf2.setName("tf2");

  KeyHandler handler = new KeyHandler();
  tf1.addKeyListener(handler);
  tf2.addKeyListener(handler);
}

public class KeyHandler extends KeyAdapter{
  public void keyTyped(KeyEvent e){
    Object source = e.getSource();
    if (source instanceof JTextField) {
      JTextField field = (JTextField)source;
      String name = field.getName();
      if ("tf1".equals(name)) {
        // Hello TextField #1
      }
    }
  }
}

代码示例来源:origin: net.sourceforge.ondex.apps/ovtk2-experimental

@Override
  public void caretUpdate(CaretEvent arg0) {
    JTextField t = (JTextField) arg0.getSource();
    String s = t.getText();
    try {
      double v = Double.parseDouble(s);
      weights.put(t.getName(), Double.valueOf(v));
      t.setBackground(Color.WHITE);
    } catch (NumberFormatException nfe) {
      t.setBackground(Color.RED);
    }
  }
});

代码示例来源:origin: bcdev/beam

public Spectrum getSpectrum() {
  final List<String> selectedElements = selectedSpectraListModel.getAllElements();
  SpectrumBand[] selectedBands = new SpectrumBand[selectedElements.size()];
  for (int i = 0; i < selectedBands.length; i++) {
    selectedBands[i] = new SpectrumBand(availableBandsMap.get(selectedElements.get(i)), true);
  }
  return new DisplayableSpectrum(nameField.getName(), selectedBands, 1);
}

代码示例来源:origin: stackoverflow.com

public class Main {

  public static void main(String[] args) {

    JTextField fName = new JTextField();
    fName.setName("First Name");
    JTextField lName = new JTextField();
    lName.setName("last Name");
    JTextField address = new JTextField();
    address.setName("Address");

    JTextField[] fields = new JTextField[] {fName, lName, address};

    StringBuilder sb = new StringBuilder("<html>");
    for (JTextField field : fields) {
      if (field.getText().isEmpty()){
        field.setBackground(Color.RED);
        sb.append("<p>").append("You haven't entered " + field.getName());
      }
    }

    JLabel label = new JLabel(sb.toString());
  }
}

代码示例来源:origin: net.sourceforge.ondex.apps/ovtk2

/**
 * @return returns the element that is currently selected as the variable.
 */
public Object getVariable() {
  String id = variable.getName();
  String type = variable.getToolTipText();
  if (type.equals("Attribute")) {
    return aog.getMetaData().getAttributeName(id);
  } else if (type.equals("Concept class")) {
    return aog.getMetaData().getConceptClass(id);
  } else if (type.equals("Relation type")) {
    return aog.getMetaData().getRelationType(id);
  } else if (type.equals("Feature")) {
    return id;
  } else {
    return null;
  }
}

代码示例来源:origin: net.officefloor.core/officebuilding

String officeNameText = openTaskOfficeName.getName();
String workNameText = openTaskWorkName.getName();
String taskNameText = openTaskTaskName.getName();
String parameterText = openTaskParameter.getName();
if ((!CompileUtil.isBlank(officeNameText)) && (!CompileUtil.isBlank(workNameText))
    && (!CompileUtil.isBlank(taskNameText))) {

相关文章

JTextField类方法