【问题标题】:Java Html Line Break Eclipse UI TextfieldJava Html 换行 Eclipse UI 文本字段
【发布时间】:2017-09-01 21:37:49
【问题描述】:

我在使用 html 在 Eclipse UI 文本字段中设置换行符时遇到问题 这是我所拥有的:

tfCharacterDescription.setText(
              "<html><div style='text-align: center;'>This is a human. <br>"
                + "The Humans has been good Warriors for centuries <br>"
                + "but they just cant get the hang of using a <br>"
                + "bow the right way.</html>"
               );

我不确定这是否是这样做的,但我似乎找不到任何其他说明。

【问题讨论】:

  • 尝试&lt;br /&gt; 而不是&lt;br&gt;。或者尝试用段落分隔行。

标签: java html eclipse


【解决方案1】:

JTextfield 不支持 HTML 标签! 而是在 JTextPane 中使用:

JTextPane tfCharacterDescription = new JTextPane();
tfCharacterDescription.setBounds(12, 12, 320, 110); //set the size
tfCharacterDescription.setContentType("text/html");//This is essential!
tfCharacterDescription.setText(
        "<html><div style='text-align: center;'>This is a human. <br>"
        + "The Humans has been good Warriors for centuries <br>"
        + "but they just cant get the hang of using a <br>"
        + "bow the right way.</html>"
    );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多