如何在 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