Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

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

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("Text Field Elements");
    JTextField tf = new JTextField(32);
    tf.setText("That's one small step for man...");
    f.getContentPane().add(tf);//ww  w  .j  av a  2 s  .c o m
    f.pack();
    f.setVisible(true);

    ((AbstractDocument) tf.getDocument()).dump(System.out);
}

From source file:Main.java

public static void main(String[] a) {
    JTextField jTextField1 = new JTextField();

    jTextField1.setText("java2s.com");

    jTextField1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("action");
        }//ww w  . j  a v  a2  s . co  m
    });
    JOptionPane.showMessageDialog(null, jTextField1);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JTextArea textarea = new JTextArea();
    textarea.setDragEnabled(true);// www  .j ava2 s  .c  om

    textarea.setText("Drag target");

    frame.getContentPane().add(BorderLayout.CENTER, textarea);

    JTextField textarea1 = new JTextField();
    textarea1.setText("Drop target");
    frame.getContentPane().add(BorderLayout.SOUTH, textarea1);

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

From source file:DnDBetweenJTextAreaAndJTextFieldDemo.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Drag and Drop Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());
    JTextField textField = new JTextField(25);
    textField.setText("www.java2s.com");
    frame.add(textField);//from w  w  w.j a v  a 2 s.c  o  m

    JTextArea textArea = new JTextArea(4, 25);
    textArea.setText("Demonstrating\ndrag and drop");
    frame.getContentPane().add(new JScrollPane(textArea));
    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    frame.pack();
    frame.setVisible(true);

}

From source file:Main.java

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

    JTextField jTextField1 = new JTextField();

    jTextField1.setText("jTextField1");
    jTextField1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("action");
        }//w w  w.j a  va  2s .co m
    });
    frame.add(jTextField1);

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

From source file:KeyTextComponent.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new KeyTextComponent(), BorderLayout.CENTER);
    JTextField field = new JTextField();
    field.setText("Click above blank area to request focus");
    frame.add(field, BorderLayout.SOUTH);
    frame.setSize(300, 100);/*from w ww  .  ja  va2s.c  o m*/
    frame.setVisible(true);
    field.requestFocus();
}

From source file:TextFieldViews.java

public static void main(String[] args) {
    try {//from w w  w. j ava2 s.  c  om
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new JFrame("Text Field View");
    JTextField tf = new JTextField(32);
    tf.setText("That's one small step for man...");
    f.getContentPane().add(tf);
    f.pack();
    f.setVisible(true);

    ViewDisplayer.displayViews(tf, System.out);
}

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  w w.  j  ava  2  s .co 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:WatermarkTextField.java

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

    JTextField textfield = new WatermarkTextField(new File("waterMarkImage.png"));
    textfield.setText("www.java2s.com");
    frame.getContentPane().add(textfield);
    frame.pack();//  ww  w  .  ja  va 2 s .  c o  m
    frame.setVisible(true);
}

From source file:Main.java

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

    JTextField textfield = new WatermarkTextField(new URL("http://www.java2s.com/style/download.png"));
    textfield.setText("www.java2s.com");
    frame.getContentPane().add(textfield);
    frame.pack();//from  ww w.j av a 2s.c  om
    frame.setVisible(true);
}