How to use html tags in JTextArea
Asked Answered
E

2

17

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?

Ernesternesta answered 2/11, 2012 at 12:20 Comment(2)
I wouldn't use a JTextArea for this but rather a JEditorPane. It has built in support for HTML.Infective
No how. Look for another component.Diapositive
A
32
  • 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,

Anticipative answered 2/11, 2012 at 12:30 Comment(1)
JTextPane with setContenType("text/html") seems to the option with fewest dependencies.String
B
2

JavaFX WebView is very powerful for rendering HTML and You can easily display javafx component(WebView) in your Swing Application by using JFXPanel. For tutorial of embedding fx in swing here is one from oracle: http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm

Thanks

Babettebabeuf answered 16/12, 2013 at 18:50 Comment(1)
how about the javafx webview....when we do the compilation for the final release would it be bigger size or it wouldn't ?Braley

© 2022 - 2024 — McMap. All rights reserved.