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) throws Exception {
    JTextComponent textComp = new JTextField("Initial Text");
    Document doc = textComp.getDocument();

    // Insert some text after the 5th character
    int pos = 5;//w  w  w.j  a v a 2  s  .co  m
    doc.insertString(pos, "some text", null);
}

From source file:Main.java

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

    // Delete the first 5 characters
    int pos = 0;//w  w  w  .  j  a va  2  s  .c om
    int len = 5;
    doc.remove(pos, len);
}

From source file:Main.java

public static void main(String[] args) {
    JTextField smallField = new JTextField(5);
    JTextField largeField = new JTextField(20);
    JPanel gui = new JPanel(new FlowLayout());
    gui.add(smallField);/*from   w  w  w  . j av a2 s .c  o m*/
    gui.add(largeField);
    JFrame f = new JFrame("Text Field Size");
    f.add(gui);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

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

    // Replace the first 3 characters with some text
    int pos = 0;/*  w  w  w.  j  av a  2 s.c  om*/
    int len = 3;
    doc.remove(pos, len);
    doc.insertString(pos, "new text", null);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel myPanel = new JPanel();
    JTextField field1 = new JTextField(10);
    JTextField field2 = new JTextField(10);
    myPanel.add(field1);/*from   w ww. j  a  v  a 2  s  .  c o m*/
    myPanel.add(field2);
    JOptionPane.showMessageDialog(null, myPanel);
    System.out.println(field1.getText() + field2.getText());
}

From source file:Main.java

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

    component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "none");

    JFrame f = new JFrame();
    f.add(component);//from w  w  w .ja  va2s  .c o  m

    f.setSize(300, 300);

    f.setVisible(true);

}

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 -"), "actionName");

    JFrame f = new JFrame();
    f.add(component);/*  ww  w .  j  av  a 2  s .c  o m*/

    f.setSize(300, 300);

    f.setVisible(true);

}

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 a"), "actionName");

    JFrame f = new JFrame();
    f.add(component);//w w w . j av a2s  . c om

    f.setSize(300, 300);

    f.setVisible(true);

}

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 www. java  2  s. c om

    f.setSize(300, 300);

    f.setVisible(true);

}

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 $"), "actionName");

    JFrame f = new JFrame();
    f.add(component);//w  ww  .ja  v a2  s .c  o m

    f.setSize(300, 300);

    f.setVisible(true);

}