簡體   English   中英

如何使文本的一部分粗體

[英]How to make only part of the text bold

你能告訴我如何才能使文本的一部分粗體化:

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");

我想只使這些字符串變粗: Product Version, Java, Runtime, System, User directory 最簡單的方法是什么?

UPDATE

我還測試了這段代碼:

TextArea dataPane = new TextArea();

    dataPane.setPrefRowCount(10);
    Text wd = new Text("Version");
    wd.setFont(Font.font ("Verdana", FontWeight.BOLD, 20));

    dataPane.appendText(wd + "1.0");
    dataPane.appendText("\nJava: " + "7");
    dataPane.appendText("\nRuntime: " + "7");
    dataPane.appendText("\nSystem: " + "Linux");
    dataPane.appendText("\nUser directory: " + "/home/dir");

我明白了: Text@149e84241.0

文本格式不正確。

您可以使用內容類型設置為html而不是文本區域的編輯器窗格。 我非常快速地將編輯器窗格放入臨時項目中,並使用了默認的變量名稱和對象屬性。 這是我如何制作我相信你正在尋找的東西:

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>");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM