|
JTextArea x = new JTextArea();
Font f = new Font( "FontName", Font.FontFace, size );
x.setFont( f );
|
Example:
JTextArea x = new JTextArea();
Font f = new Font( "Roman", Font.ITALIC, 12 );
x.setFont( f );
|
New text in the text area will now be displayed in Italic 12 points Roman font.
import java.awt.*;
import javax.swing.*;
public class SelectFont
{
public static void main(String[] args)
{
JFrame f = new JFrame("My GUI");
JTextArea x;
JScrollPane y;
Font F;
x = new JTextArea(); // Make a JTextArea
x.setEditable(true); // Output only
y = new JScrollPane(x, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
f.getContentPane().add(y); // Stick
F = new Font("Monospaced", Font.BOLD, 18);
x.setFont( F );
x.setText("Hello World");
x.append("\n\n\n");
x.append("Hello Again");
f.setSize(400, 300);
f.setVisible(true);
}
}
|