Example usage for javax.swing JTextField JTextField

List of usage examples for javax.swing JTextField JTextField

Introduction

In this page you can find the example usage for javax.swing JTextField JTextField.

Prototype

public JTextField(int columns) 

Source Link

Document

Constructs a new empty TextField with the specified number of columns.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    JTextField tField = new JTextField(10);
    ((AbstractDocument) tField.getDocument()).setDocumentFilter(new MyDocumentFilter());
    contentPane.add(tField);/*from  ww w  .  j  a  v  a  2  s  .  com*/

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:SpringFormTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Spring");
    Container contentPane = frame.getContentPane();

    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);/*  w w  w.ja v a2 s .c  o m*/

    Component left = new JLabel("Left");
    Component right = new JTextField(15);

    contentPane.add(left);
    contentPane.add(right);

    layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left);

    frame.setSize(300, 100);
    frame.show();
}

From source file:Main.java

public static void main(String[] args) {
    JLabel userLabel = new JLabel("User Name");
    JLabel passLabel = new JLabel("Password");
    JTextField userText = new JTextField(20);
    JPasswordField passText = new JPasswordField(20);
    JButton loginButton = new JButton("Login");

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridx = 0;//from w w w  .j a  v a  2  s  . c  om
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(userLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(userText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(passLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(passText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridwidth = 2;
    panel.add(loginButton, gbc);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(panel));
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    JTextField tf1 = new JTextField(10);
    panel.add(tf1);//from  w  w  w  .j  a va2s .c o  m
    JTextField tf2 = new JTextField(10);
    panel.add(tf2);

    new TextPrompt("First Name", tf1);
    new TextPrompt("Last Name", tf2);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:KeyboardFocusManagerDemo.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Border Layout");
    aWindow.setBounds(30, 30, 300, 300); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();

    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));

    Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
    set = new HashSet(set);
    KeyStroke up = KeyStroke.getKeyStroke("A");
    set.add(up);/*  w ww. j  a  va2 s  .  c o m*/
    System.out.println(set);

    p.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, set);

    aWindow.add(p);

    aWindow.setVisible(true); // Display the window
}

From source file:Main.java

public static void main(String args[]) {
    SpinnerNumberModel model = new SpinnerNumberModel(0.0, -1000.0, 1000.0, 0.1);
    JSpinner s = new JSpinner(model);
    JSpinner.NumberEditor editor = new JSpinner.NumberEditor(s);
    s.setEditor(editor);/*  w ww  . j a va  2s.  c  om*/
    JTextField stepText = new JTextField(10);
    JButton bStepSet = new JButton("Set Step");
    bStepSet.addActionListener(e -> {
        Double val = Double.parseDouble(stepText.getText().trim());
        model.setStepSize(val);
    });
    JFrame f = new JFrame();
    Container c = f.getContentPane();
    c.add(s);
    JPanel southPanel = new JPanel();
    southPanel.add(stepText);
    southPanel.add(bStepSet);
    c.add(southPanel, BorderLayout.SOUTH);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(2, 2));
    JLabel label = new JLabel("User Name:", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT);
    JTextField userNameField = new JTextField(20);
    JPasswordField passwordField = new JPasswordField();
    frame.add(label);/*w  ww  .  j a  v  a 2  s  .c o  m*/
    frame.add(userNameField);
    frame.add(label2);
    frame.add(passwordField);
    frame.setSize(200, 70);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(2, 2));
    JLabel label = new JLabel("User Name:", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT);
    JTextField userNameField = new JTextField(20);

    JPasswordField passwordField = new JPasswordField();
    passwordField.setEchoChar('#');

    frame.add(label);//from   ww  w .ja v a2 s.c o m
    frame.add(userNameField);
    frame.add(label2);
    frame.add(passwordField);
    frame.setSize(200, 70);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("SpringLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);//from  w ww. j  a va2 s  . c  o  m

    Component left = new JLabel("Name");
    Component right = new JTextField(15);

    contentPane.add(left);
    contentPane.add(right);

    layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:SpringSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("SpringLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);//from www . ja v  a  2 s  .c o m

    Component left = new JLabel("Left");
    Component right = new JTextField(15);

    contentPane.add(left);
    contentPane.add(right);
    layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left);

    frame.setSize(300, 100);
    frame.setVisible(true);
}