Created
March 11, 2013 23:04
-
-
Save figengungor/5138750 to your computer and use it in GitHub Desktop.
Java GUI >> Disabling TextField
This file contains hidden or 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 java.awt.Color; | |
| import javax.swing.JFrame; | |
| import javax.swing.JPanel; | |
| import javax.swing.JTextField; | |
| public class MyGUI extends JFrame { | |
| JPanel jp; | |
| JTextField jt; | |
| public MyGUI(){ | |
| setTitle("JTextField Disabling Example"); | |
| setSize(600,300); | |
| setVisible(true); | |
| setDefaultCloseOperation(EXIT_ON_CLOSE); | |
| jp = new JPanel(); | |
| jt = new JTextField(30); | |
| jt.setEditable(false); //disable text field, user cannot input | |
| //disabling sets bg color to grey, so we change the text field bg color to white again. | |
| jt.setBackground(Color.WHITE); | |
| jp.add(jt); | |
| add(jp); | |
| validate(); | |
| } | |
| public static void main(String [] args) { | |
| new MyGUI(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment