JTextField和HTML标签一起使用 [英] JTextField together with HTML tags

查看:139
本文介绍了JTextField和HTML标签一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Java 7.我试图通过使用HTML标签来格式化文本。我将文本传入

  JTextField text = new JTextField(); 
text.setText(< html>< body>< p>程序对以下密码执行加密操作:< / p>< / body>< / html>);

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

解决方案

JTextField does 不支持HTML 。您可以使用 JTextPane 代替:

  JTextPane text = new JTextPane() ; 
text.setContentType(text / html);
text.setText(< html>< body>< p>程序对以下密码执行加密操作:< / p>< / body>< / html>);


I am working on Java 7. I am trying to format text by using HTML tags. I pass in text into

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

But the program prints the HTML tags too. That sample of text is only an example. What might be the problem? Cheers

解决方案

JTextField does not support HTML. You could use JTextPane instead:

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

这篇关于JTextField和HTML标签一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆