Created
March 9, 2013 19:23
-
-
Save figengungor/5125400 to your computer and use it in GitHub Desktop.
Java GUI JTextField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; //For Window Frame (JFrame) | |
import java.awt.*; //For Container object | |
public class MyGUI { | |
public static void main(String[] args) { | |
new MyGUI(); | |
} | |
public MyGUI(){ | |
JFrame jf=new JFrame(); | |
jf.setTitle("My frame"); | |
jf.setSize(500,300); | |
JTextField tf1=new JTextField(10); | |
JTextField tf2=new JTextField(5); | |
JTextField tf3=new JTextField(7); | |
JTextField tf4=new JTextField(10); | |
JTextField tf5=new JTextField(10); | |
JTextField tf6=new JTextField(10); | |
tf1.setText("i am a text field"); | |
tf2.setText("i am a text field and can not be changed"); | |
tf2.setEditable(false); | |
Container pane=jf.getContentPane(); | |
pane.setLayout(new GridLayout(2,2) ); | |
tf1.setColumns(1); | |
pane.add(tf1); | |
pane.add(tf2); | |
pane.add(tf3); | |
pane.add(tf4); | |
pane.add(tf5); | |
pane.add(tf6); | |
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE); | |
jf.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment