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 |
/* Set Foreground Color of JTextField Example This java example shows how to set foreground color of JTextField's text using Java Swing JTextField class. */ import java.awt.Color; import java.awt.FlowLayout; import javax.swing.JApplet; import javax.swing.JTextField; /* <applet code="JTextFieldForegroundColorExample" width=200 height=200> </applet> */ public class JTextFieldForegroundColorExample extends JApplet{ public void init(){ //set flow layout for the applet this.getContentPane().setLayout(new FlowLayout()); //create new JTextField JTextField field = new JTextField("JTextField Foreground Color Example",20); //create new custom color Color color = Color.RED; /* * To set foreground color of JTextField's text use, * void setForeground(Color color) * method of JTextField class. */ field.setForeground(color); add(field); } } |
Add Comment