如何在 Java 中在 JTextArea 中顯示加粗文字?\n
JTextArea 類可以擴充套件JTextComponent,允許使用者在其中輸入多行文字。 JTextArea 可以生成一個CaretListener 介面,它可以監聽插入符更新事件。我們可以使用setFont()方法將字型設定到 JTextArea 中的文字。
示例
import java.awt.*;
import javax.swing.*;
public class JTextAreaTextBoldTest extends JFrame {
private JTextArea textArea;
public JTextAreaTextBoldTest() {
setTitle("JTextAreaTextBold Test");
setLayout(new BorderLayout());
textArea= new JTextArea();
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
Font boldFont=new Font(textArea.getFont().getName(), Font.BOLD, textArea.getFont().getSize());
textArea.setFont(boldFont); // bold text
add(textArea);
setSize(375, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[]args) {
new JTextAreaTextBoldTest();
}
}輸出
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP