Java Swing GUI

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.


Java Program to Change Font Color and Font Size of a JTextField:
import java.awt.*;
import javax.swing.*;

public class 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
   public static void main(String[] args)
     new TextStyle();


mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *