Java JTextField create with text

Description

Java JTextField create with text



import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

class MyPanel extends JPanel {

  public MyPanel() {
    // first name
    add(new JLabel("First Name"));
    add(new JTextField("Java"));

    // last name//from w ww.j  av a 2s. c o m
    add(new JLabel("Last Name"));
    add(new JTextField("CSS"));

    // save button
    add(new JButton("Save"));
  }

}

public class Main {
  public static void main(String[] args) {
    // create frame for Main
    JFrame frame = new JFrame("java2s.com");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(new MyPanel());
    frame.setSize(300, 210);
    frame.setVisible(true);
  }
}



PreviousNext

Related