【问题标题】:JTextField together with HTML tagsJTextField 和 HTML 标签
【发布时间】:2012-08-27 05:45:33
【问题描述】:

我正在使用 Java 7。我正在尝试使用 HTML 标记来格式化文本。我将文本传递到

JTextField text = new JTextField();
text.setText("<html><body><p>The program performs encryption operations on the following ciphers: </p></body></html>");

但是程序也会打印 HTML 标签。该文本示例只是一个示例。 可能是什么问题? 干杯

【问题讨论】:

  • 您确定要使用JTextField吗?如果您只想显示一些文本,JLabel 更适合。
  • 我在一些链接上看到 HTML 标记在 JTextField 上也可以正常工作。看起来我的应用上的文本字段看起来更好。

标签: java html swing jtextfield


【解决方案1】:

JTextField 执行not support HTML。你可以改用JTextPane

JTextPane text = new JTextPane();
text.setContentType("text/html");
text.setText("<html><body><p>The program performs encryption operations on the following ciphers: </p></body></html>");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-06
    • 2012-09-15
    相关资源
    最近更新 更多