如何在JTextArea中使用html标签 [英] How to use html tags in JTextArea

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

问题描述

当我尝试使用

  textArea.setText(< html>< font color = \red \>嗨< / font>< / html>)



<显示的文本基本上是在setText方法内写入的全部文本。但类似的东西适用于JLabel,JButton等。



我怎么能为JTextArea做这件事?

解决方案


  • 不要为 Html JTextArea c $ c>格式化对象(甚至可能,但为什么要麻烦)

  • 使用 JTextPane / JEditorPane 改为( setContentType(text / html)

  • 注意,今天在由Oracle官方API实现的Java和方法仅支持减少使用css< = Html 3.2的Html语法
  • 使用 JavaFX Html5



When I try to change color of a JTextArea using

textArea.setText("<html> <font color=\"red\"> Hi </font></html>")

, the text is shown is basically the whole text written inside setText method. But similar things work for JLabel, JButton etc.

How can I do that for a JTextArea also?

解决方案

  • don't to use JTextArea for Html formatted Object (even is possible, but why bothering)

  • use JTextPane / JEditorPane instead (setContentType("text/html"))

  • notice, todays Java and methods implemented in Official API by Oracle supporting only reduced Html syntax with css <= Html 3.2

  • use JavaFX in the case that you want/need to use todays Html5,

这篇关于如何在JTextArea中使用html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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