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

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

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

JTextField.getText介绍

暂无

代码示例

代码示例来源:origin: kiegroup/jbpm

private void addResult() {
  results.put(resultNameTextField.getText(), resultValueTextField.getText());
  resultNameTextField.setText("");
  resultValueTextField.setText("");
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static EnumMap<FilterType,String> getFilters(JPanel panel) {
 EnumMap<FilterType,String> filters = new EnumMap<>(FilterType.class);
 Component[] components = panel.getComponents();
 for(Component c : components) {
  if (c.getClass() != Box.class) {
   continue;
  }
  JComboBox filterType = (JComboBox) ((Container) c).getComponent(0);
  JTextField filterValue = (JTextField) ((Container) c).getComponent(2);
  filters.put((FilterType) filterType.getSelectedItem(), filterValue.getText());
 }
 return filters;
}

代码示例来源:origin: iluwatar/java-design-patterns

add(panel, BorderLayout.CENTER);
panel.setLayout(new GridLayout(6, 2));
panel.add(new JLabel("Name"));
panel.add(jtFields[0]);
panel.add(new JLabel("Contact Number"));
panel.add(jtFields[1]);
panel.add(new JLabel("Address"));
panel.add(jtAreas[0]);
panel.add(new JLabel("Deposit Number"));
panel.add(processButton);
clearButton.addActionListener(e -> {
 for (JTextArea i : jtAreas) {
  i.setText("");
  i.setText("");
processButton.addActionListener(e -> {
 Order order = new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2].getText(),
   jtAreas[1].getText());
 jl.setText(sendRequest(order));

代码示例来源:origin: libgdx/libgdx

panel.add(textPanel);
final JTextField textField = new JTextField(20);
textField.setText(text);
textField.setAlignmentX(0.0f);
textPanel.add(textField);
final JLabel placeholderLabel = new JLabel(hint);
placeholderLabel.setForeground(Color.GRAY);
placeholderLabel.setAlignmentX(0.0f);
textPanel.add(placeholderLabel, 0);
  listener.input(textField.getText());
} else {
  listener.canceled();

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

findButton = new JButton("Next");
findField = new JTextField("Java", 10);
textArea = new JTextArea();
textArea.setWrapStyleWord(true);
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
header.add(findField, gbc);
gbc.gridx++;
header.add(findButton, gbc);
findButton.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
    String find = findField.getText().toLowerCase();

代码示例来源:origin: wildfly/wildfly

input.add(csLabel);
txtField=new JTextField();
txtField.setPreferredSize(new Dimension(200, 30));
txtField.setBackground(Color.white);
leaveButton=new JButton("Leave");
leaveButton.setPreferredSize(new Dimension(150, 30));
buttons.add(leaveButton);
sendButton=new JButton("Send");
sendButton.setPreferredSize(new Dimension(150, 30));
buttons.add(sendButton);
clearButton=new JButton("Clear");
clearButton.setPreferredSize(new Dimension(150, 30));
clearButton.addMouseListener(new MouseAdapter() {
  String cmd=e.getActionCommand();
  if(cmd != null && !cmd.isEmpty()) {
    send(txtField.getText());
    txtField.selectAll();

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

JTextField firstName = new JTextField();
JTextField lastName = new JTextField();
JPasswordField password = new JPasswordField();
final JComponent[] inputs = new JComponent[] {
    new JLabel("First"),
    firstName,
    new JLabel("Last"),
    lastName,
    new JLabel("Password"),
    password
};
int result = JOptionPane.showConfirmDialog(null, inputs, "My custom dialog", JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
  System.out.println("You entered " +
      firstName.getText() + ", " +
      lastName.getText() + ", " +
      password.getText());
} else {
  System.out.println("User canceled / closed the dialog, result = " + result);
}

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

public class Console extends JFrame {
  private static JTextField consoleTextField;

  public Console() {
    consoleTextField = new JTextField();
    // ...
  }

  public static feedChar(char c) {
    consoleTextField.setText(consoleTextField.getText() + c.toString());
  }
}

代码示例来源:origin: marytts/marytts

private void runActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_runActionPerformed
  String inDirPath = tfInputDir.getText();
  if (inDirPath.equals("")) {
    JOptionPane.showConfirmDialog(this, "Input directory not specified!", "Info missing", JOptionPane.OK_OPTION,
    return;
  String outDirPath = tfOutputDir.getText();
  if (outDirPath.equals("")) {
    JOptionPane.showConfirmDialog(this, "Output directory not specified!", "Info missing", JOptionPane.OK_OPTION,
  boolean bestOnly = cbBestOnly.isSelected();
    whichChannel = AudioPlayer.STEREO;
  boolean downSample = cbDownsample.isSelected();
  int targetSampleRate = Integer.parseInt((String) comboSampleRate.getSelectedItem());
  String soxPath = tfSoxPath.getText();
  if (downSample && !new File(soxPath).exists()) {
    JOptionPane.showConfirmDialog(this, "Please indicate location of 'sox' tool\n"
  boolean maximiseAmplitude = cbGlobalAmplitude.isSelected();
  double targetMaxAmplitude = Double.parseDouble(((String) comboMaxAmplitude.getSelectedItem()).substring(0, 3));
  boolean trimSilences = cbTrimSilences.isSelected();

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

JButton yourButton= new JButton("Click me");
JTextField textField = new JTextField("Some initial value Textfield 1");
JTextField textField2 = new JTextField("Some initial value Textfield 2");
yourButton.addActionListener(new ActionListener()
{
 public void actionPerformed(ActionEvent e)
 {
  // Get value of textfield 1
   String currValue = textField.getText();
  // Set value for textfield 2
  textField2.setText(currValue); 
 }
});

代码示例来源:origin: kiegroup/jbpm

private void addResult() {
  String name = resultNameField.getText();
  String value = resultValueField.getText();
  if ("".equals(name) || "".equals(value)) {
    JOptionPane.showMessageDialog(this,
      "Name or value of result may not be null!", "Error", JOptionPane.ERROR_MESSAGE);
    return;
  }
  Result result = new Result(name, value);
  if (results.contains(result)) {
    JOptionPane.showMessageDialog(this,
      "Cannot add result more than once!", "Error", JOptionPane.ERROR_MESSAGE);
    return;
  }
  results.add(result);
  reloadResultList();
  resultNameField.setText("");
  resultValueField.setText("");
}

代码示例来源:origin: libgdx/libgdx

void generate () {
  final String name = ui.form.nameText.getText().trim();
  if (name.length() == 0) {
    JOptionPane.showMessageDialog(this, "Please enter a project name.");
    return;
  final String pack = ui.form.packageText.getText().trim();
  if (pack.length() == 0) {
    JOptionPane.showMessageDialog(this, "Please enter a package name.");
    return;
    JOptionPane.showMessageDialog(this, "Invalid package name");
    return;
  final String clazz = ui.form.gameClassText.getText().trim();
  final String destination = ui.form.destinationText.getText().trim();
  final String sdkLocation = ui.form.sdkLocationText.getText().trim();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    for (String subIncompat : incompatList) {
      JLabel label = new JLabel(subIncompat);
      label.setAlignmentX(Component.CENTER_ALIGNMENT);
      panel.add(label);
    pane.setOpaque(false);
    pane.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(pane);

代码示例来源:origin: deathmarine/Luyten

private boolean search(String bulk) {
  String a = textField.getText();
  String b = bulk;
  if (regex.isSelected())
    return Pattern.matches(a, b);
  if (wholew.isSelected())
    a = " " + a + " ";
  if (!mcase.isSelected()) {
    a = a.toLowerCase();
    b = b.toLowerCase();
  }
  if (b.contains(a))
    return true;
  return false;
}

代码示例来源:origin: osmdroid/osmdroid

@Override
   public void actionPerformed(final ActionEvent e) {
     if (Desktop.isDesktopSupported()) {
        try {
          Desktop.getDesktop().browse(new URI(String.format(txtURL.getText(), 0, 0, 0)));
        } catch (final Throwable t) {
          t.printStackTrace();
        }
     } else {
        JOptionPane.showMessageDialog(null, "Could not open browser.");
     }
   }
});

代码示例来源:origin: stanfordnlp/CoreNLP

public void actionPerformed(ActionEvent arg0) {
 try {
  HeadFinder hf = Preferences.lookupHeadFinder(headfinderPicker.getSelectedItem().toString());
  if (hf == null) {
   JOptionPane.showMessageDialog(PreferencesPanel.this, "Sorry, there was an error finding or instantiating the head finder. Please choose another head finder.", "Head Finder Error", JOptionPane.ERROR_MESSAGE);
   throw new Exception("Headfinder error");
  TreeReaderFactory trf = Preferences.lookupTreeReaderFactory(trfPicker.getSelectedItem().toString());
  if (trf == null) {
   JOptionPane.showMessageDialog(PreferencesPanel.this, "Sorry, there was an error finding or instantiating the tree reader factory. Please choose another tree reader factory.", "Tree Reader Factory Error", JOptionPane.ERROR_MESSAGE);
   throw new Exception("Tree reader factory error");
  Integer textSize = checkNumberFormat(size, PreferencesPanel.FONT_ERROR);
  syncFromPrefPanel(fontPicker.getSelectedItem().toString(),
    textSize,
    ((ColorIcon) defaultColorButton.getIcon()).getColor(),
    historySize,
    maxMatchSize,
    tsurgeonCheck.isSelected(), matchPortion.isSelected(), hf, trf, setEncoding.getText().trim());
  PreferencesPanel.this.setVisible(false);
 } catch(NumberFormatException e) {
   JOptionPane.showMessageDialog(prefPanel, "Please enter an integer greater than 0 for the font size.", "Font size error", JOptionPane.ERROR_MESSAGE);
  else if (e.getMessage() == PreferencesPanel.HISTORY_ERROR)
   JOptionPane.showMessageDialog(prefPanel, "Please enter an integer greater than or equal to 0 for the number of recent matches to remember.", "History size error", JOptionPane.ERROR_MESSAGE);

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

JTextField username = new JTextField();
JTextField password = new JPasswordField();
Object[] message = {
  "Username:", username,
  "Password:", password
};

int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
  if (username.getText().equals("h") && password.getText().equals("h")) {
    System.out.println("Login successful");
  } else {
    System.out.println("login failed");
  }
} else {
  System.out.println("Login canceled");
}

代码示例来源:origin: bonnyfone/vectalign

private boolean export(){
  lastSupportVectorCompat = checkVectorCompat.isSelected();
  lastDuration = txtDuration.getText();
  if(lastOuputDir != null){
    //Chose prefix
    String defaultPrefix = "vectalign";
    String prefix = txtPrefix.getText();
    if(prefix == null || prefix.trim().equals("")){
      prefix = "";
    }
    lastPrefix = prefix.toLowerCase();
    //Export
    boolean success = AnimatedVectorDrawableUtils.export(lastOuputDir, lastDuration, lastSupportVectorCompat,
        lastPrefix, solution, stroke, fill, strokeColor, strokeWidth, fillColor,
        DEFAULT_EXPORT_SIZE, DEFAULT_EXPORT_SIZE, viewPortWidth, viewPortHeight);
    if(success)
      JOptionPane.showMessageDialog(VectAlignExportDialog.this, "Export completed ("+lastOuputDir.getAbsolutePath() +")", "VectAlign Export", JOptionPane.INFORMATION_MESSAGE);
    else
      JOptionPane.showMessageDialog(VectAlignExportDialog.this, "Unable to export files to "+lastOuputDir.getAbsolutePath() , "VectAlign Export", JOptionPane.ERROR_MESSAGE);
    return success;
  }
  else
    JOptionPane.showMessageDialog(VectAlignExportDialog.this, "Specify a valid ouput directory." , "VectAlign Export", JOptionPane.ERROR_MESSAGE);
  return false;
}

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

searchField = new JTextField();
    String value = searchField.getText();
panel.add(searchField);
panel.add(scroll);

代码示例来源:origin: gocd/gocd

okButton.addActionListener(newEvent -> {
  try {
    AgentBootstrapperArgs newArgs = new AgentBootstrapperArgs(
        new URL(serverTextField.getText()),
        fileBrowser.getFile(), sslModeComponent.getSslMode());
      new ServerUrlValidator().validate("The server url", newArgs.getServerUrl().toExternalForm());
    } catch (ParameterException e) {
      JOptionPane.showMessageDialog(getContentPane(), e.getMessage(), "Invalid server url", JOptionPane.ERROR_MESSAGE);
      return;
        new CertificateFileValidator().validate("The server root certificate", newArgs.getRootCertFile().getPath());
      } catch (ParameterException e) {
        JOptionPane.showMessageDialog(getContentPane(), e.getMessage(), "Invalid server root certificate", JOptionPane.ERROR_MESSAGE);
        return;
    JOptionPane.showMessageDialog(getContentPane(), "The server url must be an HTTPS url and must begin with https://", "Invalid server url", JOptionPane.ERROR_MESSAGE);

代码示例来源:origin: opentripplanner/OpenTripPlanner

when = dateFormat.parse(searchDate.getText());
} catch (ParseException e) {
  searchDate.setText("Format: " + dateFormat.toPattern());
  return;
RoutingRequest options = new RoutingRequest(modeSet);
options.setArriveBy(arriveByCheckBox.isSelected());
options.setWalkBoardCost(Integer.parseInt(boardingPenaltyField.getText()) * 60); // override low 2-4 minute values
options.setBikeBoardCost(Integer.parseInt(boardingPenaltyField.getText()) * 60 * 2);
options.setMaxWalkDistance(Integer.parseInt(maxWalkField.getText()));
options.setDateTime(when);
options.setFromString(from);
options.setToString(to);
options.walkSpeed = Float.parseFloat(walkSpeed.getText());
options.bikeSpeed = Float.parseFloat(bikeSpeed.getText());
options.softWalkLimiting = ( softWalkLimiting.isSelected() );
options.softWalkPenalty = (Float.parseFloat(softWalkPenalty.getText()));
options.softWalkOverageRate = (Float.parseFloat(this.softWalkOverageRate.getText()));
options.numItineraries = 1;
System.out.println("--------");
options.numItineraries = ( Integer.parseInt( this.nPaths.getText() ) );
showGraph.setSPTFlattening( Float.parseFloat(sptFlattening.getText()) );
showGraph.setSPTThickness( Float.parseFloat(sptThickness.getText()) );
showGraph.redraw();

相关文章

微信公众号

最新文章

更多

JTextField类方法