Java 如何仅使部分文本加粗
你能告诉我如何只将部分文本加粗吗:Java 如何仅使部分文本加粗,java,javafx-2,javafx,javafx-8,Java,Javafx 2,Javafx,Javafx 8,你能告诉我如何只将部分文本加粗吗: TextArea dataPane = new TextArea(); dataPane.appendText("Product Version: " + "1.0"); dataPane.appendText("\nJava: " + "7"); dataPane.appendText("\nRuntime: " + "7"); dataPane.appendText("\nSy
TextArea dataPane = new TextArea();
dataPane.appendText("Product Version: " + "1.0");
dataPane.appendText("\nJava: " + "7");
dataPane.appendText("\nRuntime: " + "7");
dataPane.appendText("\nSystem: " + "Linux");
dataPane.appendText("\nUser directory: " + "/home/dir");
我只想将这些字符串设为粗体:产品版本、Java、运行时、系统、用户目录
?最简单的方法是什么
更新
我还测试了这段代码:
TextArea dataPane=新建TextArea()
我明白了:Text@149e84241.0
文本格式不正确 您可以使用内容类型设置为html的编辑器窗格,而不是文本区域。我很快就在一个scratch项目中加入了一个编辑器窗格,只使用了默认的变量名和对象属性。以下是我如何制作我相信您正在寻找的产品:
jEditorPane1.setContentType("text/html"); //by default this is text/plain
//use margin-top and margin-bottom to prevent gaps between paragraphs
//or actually customize them to create space if you desire so
jEditorPane1.setText("<p style='margin-top:0pt;'><b>Product Version:</b> 1.0</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>Java:</b> 7</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>Runtime:</b> 7</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>System:</b> Linux</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>User directory:</b> /home/dir</p>");
jEditorPane1.setContentType(“text/html”)//默认情况下,这是文本/纯文本
//使用页边距顶部和页边距底部以防止段落之间出现间隙
//或者,如果你愿意的话,可以定制它们来创造空间
jEditorPane1.setText(“Java:7
”+
“运行时:7
”+
“系统:Linux
”+
“用户目录:/home/dir
”;
不能使用TextArea
jEditorPane1.setContentType("text/html"); //by default this is text/plain
//use margin-top and margin-bottom to prevent gaps between paragraphs
//or actually customize them to create space if you desire so
jEditorPane1.setText("<p style='margin-top:0pt;'><b>Product Version:</b> 1.0</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>Java:</b> 7</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>Runtime:</b> 7</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>System:</b> Linux</p>" +
"<p style='margin-top:0pt; margin-bottom:0pt;'><b>User directory:</b> /home/dir</p>");