Home > Enterprise >  Java swing set font color with HTML tag but cyan and magenta color don't work
Java swing set font color with HTML tag but cyan and magenta color don't work

Time:02-15

enter image description here

Hello I'm trying to change font color in JLabel with html tag like this, <font color=" fontColor "> every other color such as red, orange, blue, green, lightGray, yellow, white, and black but cyan and magenta do not.

Does anyone know why those two special colors don't work in java?

Thank you!

CodePudding user response:

Unfortunately, the Swing HTML renderer is quite old. It conforms to HTML 3.2 and CSS 1.0.

The color attribute of <font> is parsed using the non-public CSS.stringToColor method, which only recognizes 17 color names: Black, Silver, Gray, White, Maroon, Red, Purple, Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal, Aqua, and Orange.

For what it’s worth, JavaFX is a more modern UI library which has a WebView component that uses WebKit for rendering, and thus has much more up-to-date HTML and CSS support.

CodePudding user response:

Never mind, I just figured out the solution. But if anyone has the same issue, try to use #00FFFF instead of 'cyan'!

  • Related