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[] argv) {
    JTextField textfield = new JTextField(10);
    textfield.setHorizontalAlignment(JTextField.RIGHT);
}

From source file:Main.java

public static void main(String[] argv) {
    JTextField textfield = new JTextField("Initial Text");

    // Left-justify the text
    textfield.setHorizontalAlignment(JTextField.LEFT);

    // Center the text
    textfield.setHorizontalAlignment(JTextField.CENTER);

    // Right-justify the text
    textfield.setHorizontalAlignment(JTextField.RIGHT);

}

From source file:Main.java

public static void main(String[] argv) {
    JTextField textfield = new JTextField(10);
    textfield.setHorizontalAlignment(JTextField.RIGHT);

    JOptionPane.showMessageDialog(null, textfield);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JTextField textfield = new JTextField(10);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            textfield.requestFocus();//  w ww.  j  av  a2s. com
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JTextField textfield = new JTextField(10);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            textfield.requestFocus();//ww w .  j a va 2s. co m
        }
    });

}

From source file:Main.java

public static void main(String[] args) {
    JTextField tf = new JTextField("");
    tf.setInputVerifier(new MyInputVerifier());

}

From source file:Main.java

public static void main(String[] args) {
    JTextField tf = new JTextField("mm");
    tf.setPreferredSize(tf.getPreferredSize());
    tf.setText("");

    JPanel pHacked = new JPanel();
    pHacked.add(tf);/*from   w ww .j  a v a 2 s .  c  o  m*/

    JPanel pStock = new JPanel();
    pStock.add(new JTextField(2));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new java.awt.GridLayout(0, 1));
    frame.add(pHacked);
    frame.add(pStock);
    frame.setSize(150, 150);
    frame.setVisible(true);
    tf.requestFocus();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextField textfield = new JTextField(25);

    // Create label and associate with text field
    JLabel label = new JLabel("Text Label");
    label.setDisplayedMnemonic(KeyEvent.VK_L);
    label.setLabelFor(textfield);//from  ww w.jav  a  2 s .c om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextComponent textComp = new JTextField("Initial Text");
    Document doc = textComp.getDocument();

    // Append some text
    doc.insertString(doc.getLength(), "some text", null);
}

From source file:Main.java

public static void main(String[] argv) {
    JTextField component = new JTextField(10);

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("typed X"), "none");

    JFrame f = new JFrame();
    f.add(component);/*from  w w  w. j a  va  2  s .  com*/
    f.setSize(300, 300);
    f.setVisible(true);
}