How to Change Font Color and Font Size of a JTextField in Java Swing
In this tutorial, we are going to see how to change the font color and font size of a JTextField in Java Swing. JTextField is a lightweight component that allows editing a single line of text.
![](https://stackhowto.com/wp-content/uploads/2021/08/how-to-change-font-color-and-font-size-of-a-jtextfield-in-java-swing.gif)
[st_adsense]
Java Program to Change Font Color and Font Size of a JTextField:
import java.awt.*; import javax.swing.*; public class TextStyle { TextStyle() { JFrame frame = new JFrame(); frame.setLayout(new GridLayout(4,1)); JTextField text = new JTextField(); // Change text font size text.setFont(new Font("Serif",Font.BOLD,30)); // Change text font color text.setForeground(Color.RED); frame.add(text); frame.setSize(300,200); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new TextStyle(); } }
Output:
![](https://stackhowto.com/wp-content/uploads/2021/08/how-to-change-font-color-and-font-size-of-a-jtextfield-in-java-swing.gif)
[st_adsense]