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

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

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

JTextField.<init>介绍

暂无

代码示例

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

import javax.swing.*;

public class JOptionPaneMultiInput {
  public static void main(String[] args) {
   JTextField xField = new JTextField(5);
   JTextField yField = new JTextField(5);

   JPanel myPanel = new JPanel();
   myPanel.add(new JLabel("x:"));
   myPanel.add(xField);
   myPanel.add(Box.createHorizontalStrut(15)); // a spacer
   myPanel.add(new JLabel("y:"));
   myPanel.add(yField);

   int result = JOptionPane.showConfirmDialog(null, myPanel, 
        "Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);
   if (result == JOptionPane.OK_OPTION) {
     System.out.println("x value: " + xField.getText());
     System.out.println("y value: " + yField.getText());
   }
  }
}

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

/**
 * Constructor
 */
public Client() {
 super("Client System");
 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 setSize(300, 300);
 jl = new JLabel("RUNNING...");
 jtFields = new JTextField[3];
 for (int i = 0; i < 3; i++) {
  jtFields[i] = new JTextField();
 }
 jtAreas = new JTextArea[2];
 for (int i = 0; i < 2; i++) {
  jtAreas[i] = new JTextArea();
 }
 clearButton = new JButton("Clear");
 processButton = new JButton("Process");
 setup();
}

代码示例来源: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: jMonkeyEngine/jmonkeyengine

private JPanel createSearchPanel(final FilteredJList classes) {
  JPanel search = new JPanel();
  search.setLayout(new BorderLayout());
  search.add(new JLabel("Choose a Demo to start:      Find: "),
      BorderLayout.WEST);
  final javax.swing.JTextField jtf = new javax.swing.JTextField();
  jtf.getDocument().addDocumentListener(new DocumentListener() {
    public void removeUpdate(DocumentEvent e) {

代码示例来源:origin: fossasia/neurolab-desktop

JPanel content = new JPanel();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
frame = new JFrame();
frame.setSize(400, 600);
frame.setLocationRelativeTo(null);
JScrollPane mPane = new JScrollPane(messageOutputTextList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ipField = new JTextField("127.0.0.1");
portField = new JTextField("7077");
forwardButton = new JButton();
forwardButton.setText("forward");
forwardButton.addActionListener(new ActionListener()
JButton stopButton = new JButton();
stopButton.setText("exit");
stopButton.addActionListener(new ActionListener()
statusLabel = new JLabel("mute");
statusLabel.setBackground(new Color(255,0,0));
JPanel buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
buttons.add(statusLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

final Object benchmarkResult = mixedCheckBox.getBenchmarkResult();
JPanel mainPanel = new JPanel(new BorderLayout());
String benchmarkResultTextFieldText = null;
if (benchmarkResult instanceof SolverBenchmarkResult) {
  benchmarkResultTextFieldText = solverBenchmarkResultNameMapping.get(benchmarkResult);
final JTextField benchmarkResultNameTextField = new JTextField(benchmarkResultTextFieldText == null ? benchmarkResult.toString()
    : benchmarkResultTextFieldText, 30);
mainPanel.add(benchmarkResultNameTextField, BorderLayout.WEST);
JButton confirmRenameButton = new JButton(renamedAction);
mainPanel.add(confirmRenameButton, BorderLayout.EAST);
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

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

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JPanel pnl = new JPanel(new MigLayout("wrap"));
JTextField field = new JTextField(10);
JTextArea area = new JTextArea(10, 10);        
pnl.add(field, "pushx, growx");
pnl.add(new JScrollPane(area), "push, grow");
add(pnl);
  public void run() {
    MigLayoutPushEx ex = new MigLayoutPushEx();
    ex.setVisible(true);

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

import java.awt.*;
import javax.swing.*;

 public class DemoJTextFieldWithLimit extends JApplet{
  JTextField textfield1;
  JLabel label1;

  public void init() {
   getContentPane().setLayout(new FlowLayout());
   //
   label1 = new JLabel("max 10 chars");
   textfield1 = new JTextField(15);
   getContentPane().add(label1);
   getContentPane().add(textfield1);
   textfield1.setDocument
    (new JTextFieldLimit(10));
   }
}

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

JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new FindTextPane());
findButton = new JButton("Next");
findField = new JTextField("Java", 10);
textArea = new JTextArea();
textArea.setWrapStyleWord(true);

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

JTextField textField = new JTextField(10);
JPanel panel = new JPanel();
panel.add(textField);

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

frame = new JFrame("JTextField events");
frame.getContentPane().setLayout(new FlowLayout());
JTextField field1 = new JTextField(10);
field1.addActionListener(new Events());
frame.getContentPane().add(new JLabel("Field with no action command set"));
frame.getContentPane().add(field1);
JTextField field2 = new JTextField(10);
field2.addActionListener(new Events());
field2.setActionCommand("my action command");
frame.getContentPane().add(new JLabel("Field with an action command set"));
frame.getContentPane().add(field2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(220, 150);
frame.setResizable(false);

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

public void resetResourceListPanel() {
  if (resourceListPanel != null) {
    remove(resourceListPanel);
  }
  resourceListPanel = new JPanel(new GridLayout(1, resourceList.size()));
  resourceFieldMap = new LinkedHashMap<>(resourceList.size());
  for (MrResource resource : resourceList) {
    long maximumCapacity = machine == null ? 0L : machine.getMachineCapacity(resource).getMaximumCapacity();
    JTextField resourceField = new JTextField("0 / " + maximumCapacity);
    resourceFieldMap.put(resource, resourceField);
    resourceField.setEditable(false);
    resourceField.setEnabled(false);
    resourceListPanel.add(resourceField);
  }
  add(resourceListPanel, BorderLayout.CENTER);
}

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

private JTextField firstText = new JTextField("Desired TextField");
private JButton copyButton = new JButton("Copy text from JTextFields");
private CopyTextControl2 control;
 add(firstText);
 add(copyButton);

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

FileBrowser() {
  super();
  setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
  textField = new JTextField(15);
  textField.setEnabled(false);
  add(textField);
  browse = new JButton("Browse");
  add(browse);
  browse.addActionListener(e -> {
    JFileChooser jFileChooser = new JFileChooser(file != null ? file.getParentFile() : null);
    int returnVal = jFileChooser.showOpenDialog(FileBrowser.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      setFile(jFileChooser.getSelectedFile());
    }
  });
}

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

final JFrame frame = new JFrame("JCheckBox Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(JCheckAndTextPane.newInstance());
frame.setSize(new Dimension(250, 75)); // for demonstration purposes only
  final JTextField textField = new JTextField("Enabled");
  final JCheckBox checkBox = new JCheckBox("Enable", true);
  checkBox.addItemListener(new ItemListener(){

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

private void createView() {
  JPanel controlsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
  serverTextField = new JTextField("");
  serverTextField.setColumns(15);
  serverTextField.selectAll();
  JPanel textPanel = new JPanel(new GridLayout(4, 2, 0, 10));
  textPanel.add(new JLabel("Go Server Hostname or IP"));
  textPanel.add(serverTextField);
  textPanel.add(new JLabel("SSL Mode"));
  sslModeComponent = new SslModeComponent();
  textPanel.add(sslModeComponent);
  textPanel.add(new JLabel("Server root certificate"));
  fileBrowser = new FileBrowser();
  textPanel.add(fileBrowser);
  controlsPanel.add(textPanel);
  getContentPane().add(controlsPanel, BorderLayout.NORTH);
  JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
  okButton = new JButton("OK");
  buttonPanel.add(okButton);
  getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}

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

private void uiLayout (final SetupCheckBox gwtCheckBox) {
  content = new JPanel(new GridBagLayout());
  content.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
  bottomPanel = new JPanel(new GridBagLayout());
  buttonPanel = new JPanel(new GridBagLayout());
  buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  JLabel settings = new JLabel("Settings");
  JLabel description = new JLabel("Description");
  settings.setForeground(new Color(255, 255, 255));
  description.setForeground(new Color(255, 255, 255));
  content.add(description, new GridBagConstraints(3, 0, 1, 1, 1, 1, NORTH, HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  JLabel mavenLabel = new JLabel("Maven Mirror Url");
  JLabel mavenDesc = new JLabel("Replaces Maven Central with this repository");
  mavenTextField = new JTextField(15);
  mavenTextField.setMinimumSize(mavenTextField.getPreferredSize());
  mavenLabel.setForeground(new Color(170, 170, 170));

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

JLabel label = new JLabel("Filter Level:");
gridbag.setConstraints(label, c);
add(label);
label = new JLabel("Filter Thread:");
gridbag.setConstraints(label, c);
add(label);
label = new JLabel("Filter Logger:");
gridbag.setConstraints(label, c);
add(label);
final JTextField threadField = new JTextField("");
threadField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
final JTextField catField = new JTextField("");
catField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
final JTextField ndcField = new JTextField("");
ndcField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
final JTextField msgField = new JTextField("");
msgField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {

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

private JPanel createScorePanel() {
  JPanel scorePanel = new JPanel(new BorderLayout(5, 0));
  JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
  showConstraintMatchesDialogAction = new ShowConstraintMatchesDialogAction();
  showConstraintMatchesDialogAction.setEnabled(false);
  buttonPanel.add(new JButton(showConstraintMatchesDialogAction));
  indictmentHeatMapToggleButton = new JToggleButton(
      solutionPanel.isUseIndictmentColor() ? indictmentHeatMapTrueIcon : indictmentHeatMapFalseIcon,
  buttonPanel.add(indictmentHeatMapToggleButton);
  scorePanel.add(buttonPanel, BorderLayout.WEST);
  scoreField = new JTextField("Score:");
  scoreField.setEditable(false);
  scoreField.setForeground(Color.BLACK);

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

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JPanel pnl = new JPanel(new MigLayout("wrap", "[grow]", "[][grow]"));
JTextField field = new JTextField(10);
JTextArea area = new JTextArea(10, 10);
pnl.add(field, "growx");
pnl.add(new JScrollPane(area), "grow");
add(pnl);
  public void run() {
    MigLayoutGrowEx ex = new MigLayoutGrowEx();
    ex.setVisible(true);

相关文章

JTextField类方法