Program to get JTextArea font information


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 −

Updated on: 30-Jul-2019

54 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements