Set font for JTextArea in Java
Description
The following code shows how to set font for JTextArea.
Example
import java.awt.Font;
/* w w w. j av a 2s . c o m*/
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Main extends JFrame {
String davidMessage = "\u05E9\u05DC\u05D5\u05DD \u05E2\u05D5\u05DC\u05DD";
public Main() {
JTextArea textArea = new JTextArea(davidMessage);
textArea.setFont(new Font("LucidaSans", Font.PLAIN, 40));
add(textArea);
}
public static void main(String[] args) {
JFrame frame = new Main();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »