Search code examples
javaswingfontsjtextfieldjtextarea

changing JTextField formatting


I want to change the format of this JTextField especially the font size and color.

here is the code :

JTextField textField = new JTextField(10);
JTextArea msgArea = new JTextArea(10, 30);

Solution

  • You could change the color with by setting a Font color.

    Font f = new Font("Arial", Font.BOLD, 15);
    
    textField.setFont(f);
    textField.setForeground(Color.RED);
    
    msgArea.setFont(f);
    msgArea.setForeground(Color.BLUE);