如何在JTextArea中设置样式(制作粗体)文本? [英] How to stylize (make bold) text in a JTextArea?

查看:271
本文介绍了如何在JTextArea中设置样式(制作粗体)文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JTextArea txt = new JTextArea();
    StringBuffer sb = new StringBuffer();
    sb.append("Employee Information");
    sb.append("\n");
    sb.append("Name:");
    txt.setText(sb.toString());

此处我需要将员工信息设置为BOLD格式。该怎么做..
我试过这样

Here I need to set "Employee Information" to BOLD format..How to do that.. I tried like this

 sb.append("<html><b>Employee Information</b></html>");

但它正常打印文本...如何制作粗体?

But its printing the text normally... how to make bold?

推荐答案

JText区域是一个纯文本区域,对于样式文本区域,您需要像 JEditorPane 或者JTextPane,看看文档

The JText Area is a plain text area, for styled text areas you need something like JEditorPane or JTextPane, take a look at the Documentation

这篇关于如何在JTextArea中设置样式(制作粗体)文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆