1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
/* Create New JTextField Example This java example shows how to create new JTextField using Java Swing JTextField class. */ import java.awt.FlowLayout; import javax.swing.JApplet; import javax.swing.JTextField; /* <applet code="CreateNewJTextFieldExample" width=200 height=200> </applet> */ public class CreateNewJTextFieldExample extends JApplet{ public void init(){ //set flow layout for the applet this.getContentPane().setLayout(new FlowLayout()); /* * To create new JTextField use, * JTextField() * constructor. * * This will create new empty JTextField. */ JTextField field1 = new JTextField(); /* * To create new JTextField with default text, use * JTextField(String text) * constructor. * * This will create new JTextField with default text. */ JTextField field2 = new JTextField("JTextField Default Text"); /* * To create new JTextField with specified number of columns, use * JTextField(int columns) * constructor. * * This will create new empty JTextField with specified number of * columns. */ JTextField field3 = new JTextField(10); /* * To create new JTextField with default text and columns use * JTextField(String text, int columns) * constructor. * * This will create new JTextField with default text and specified * number of columns. */ JTextField field4 = new JTextField("JTextField Default Text", 20); /* * Add text field to the applet */ add(field1); add(field2); add(field3); add(field4); } } |
Add Comment