Java Html换行Eclipse UI文本字段

时间:2016-03-03 13:04:31

标签: java html eclipse

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

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

我不确定这是不是这样做但我似乎找不到任何其他说法。

1 个答案:

答案 0 :(得分:0)

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