javacodex.com
Java Examples
Java Examples
memu home questions

JTextField

A JTextField can handle (display and/or edit) one line of plain text.

Source: (JTextFieldExample.java)

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
 
public class JTextFieldExample {
 
  public static void main(String[] arguments) {
 
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("JTextField Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(250,250); 
 
    frame.setLayout(new FlowLayout());
 
    final JTextField input = new JTextField("input");
    input.setColumns(20);
 
    final JTextField output = new JTextField("output");
    output.setColumns(20);
 
    input.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        output.setText(input.getText());
      }
    });
 
    frame.add(input);
    frame.add(output);
 
    frame.setVisible(true);
  }
}
 

Output:

$ java JTextFieldExample
Output



Contact: javacodex@yahoo.com