Search code examples
javahtmlswingfontsjlabel

Programmatically detect if Swing HTML markup rendered correctly


Is there a way to detect if a (synthatically correct) HTML rendered in a JLabel has rendered succesfully, and is displaying all intended Glyph(s)

I have the following HTML String:

<html><h3>Title</h3><ul><li><b>S</b>tuff</li><li><b>S</b>taff</li><li><b>S</b>tiff</li></ul></html>

That renders:


Title

  • Stuff
  • Staff
  • Stiff


However, in an application, the same HTML inside a JLabel rendered as: an example

As it can be seen, nothing is bold, my custom HTML parser can check for HTML issues, and it detects that String as correct, it then parses "correctly", and renders the Glyph(s), however, the bold Glyph(s) are being replaced by their default plain Glyph(s).

Is there a way to programatically detect that the Glyph was not used, and search for the Glyph, and replace it?

Also worth noticing:

  • Similar question(s) have not yielded significant result(s). I can confirm that the HTML is always correct, and even using the "test HTML", the issue occurred.
  • The Font contains the bold face
  • Other HTML markup is being rendered correctly elsewhere(p, i, h, etc.)
  • The HTML is from other supplier(s), and should not be altered/handled/defined

Solution

  • JLabel text by default is already bold. You cannot double bold it, you can only unbold it and rebold it.

    Try:

    <html><body style="font-weight: normal"><h3>Title</h3><ul><li><b>S</b>tuff</li><li><b>S</b>taff</li><li><b>S</b>tiff</li></ul></body></html>