Program to get JTextArea font information

Java 8Object Oriented ProgrammingProgramming

Let’s say the following is our JTextArea −

JTextArea textArea = new JTextArea("This is demo text.");

Now, get the font using the Font class getFont() method as shown below −

Font font = textArea.getFont();
System.out.println("Font = "+font);

The following is an example to get JTextArea font information in Java −

Example

package my;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.*;
public class SwingDemo {
   SwingDemo(){
      JFrame frame = new JFrame();
      JTextArea textArea = new JTextArea("This is demo text.");
      Font font = textArea.getFont();
      System.out.println("Font = "+font);
      frame.add(textArea);
      frame.setSize(550,300);
      frame.setLayout(new GridLayout(2, 2));
      frame.setVisible(true);
   }
   public static void main(String args[]) {
      new SwingDemo ();
   }
}

Output

The Font info is displayed in Console −

raja
Published on 06-Jun-2019 13:26:27
Advertisements