7
我想將不同的字體行添加到JTextArea中,但最後一種字體似乎會覆蓋另一種字體。更改JTextArea中不同行的字體
請幫助...
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class test extends JFrame {
private static JTextArea referenceTextArea = new JTextArea(10, 10);
private JPanel panel = new JPanel();
public test() {
this.add(panel);
panel.add(referenceTextArea);
}
public static void textTest() {
referenceTextArea.setFont(new Font("Serif", Font.BOLD, 15));
referenceTextArea.append("line1");
referenceTextArea.append("\n");
referenceTextArea.setFont(new Font("Serif", Font.ITALIC, 30));
referenceTextArea.append("line2");
referenceTextArea.append("\n");
}
public static void main(String[] args) {
test frame = new test();
frame.setVisible(true);
frame.setSize(400, 400);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
textTest();
}
}