Below example shows how to set JTextField setForegroundColor for JTextField SwingClass. Syntax: field.setForeground(Color.BLUE); se...
Below example shows how to set JTextField setForegroundColor for JTextField SwingClass.
Syntax:
field.setForeground(Color.BLUE);
setForeGround Example
/** * * @author Eric * Blog:www.techoverload.net * This Example shows how to set JTextField foreground color. * Method: field.setForegroundColor(Color.BLUE) */ import java.awt.Color; import javax.swing.JFrame; import javax.swing.JTextField; import java.awt.Dimension; import java.awt.FlowLayout; public class JTextFieldExample extends JFrame{ public JFrame frame; public JTextField field; JTextFieldExample() { super("JTextField methods"); setLayout(new FlowLayout()); //create JTextField object field=new JTextField(); field.setColumns(30); field.setForeground(Color.BLUE); add(field); setSize(new Dimension(300,300)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String args[]) { new JTextFieldExample(); } }