Question

I set this text to JTextPane, with contentType text/html.

<!doctype html>
<html>
  <head><title>Test document</title></head>
  <body style="font-family:monospace">
    <p title="t1" style="color: #FF0000;">
      This is <span title="t2" style="color: #00FF00;">new <span style="color: #0000FF;">more</span> title</span> test
    </p>
  </body>
</html>

My goal is, getting title attribute to display as ToolTip when mouse-over. I learned that it is possible overriding JTextPane.getToolTipText(MouseEvent event) and using JTextComponent.viewToModel(Point pt).

So far, This is and test displays tooltip t1, and new and title displays tooltip t2, as expected.

However, I can't retrieve title="t2" when I mouse-over the word more; instead, it displays tooltip t1.

Using the JEditorPaneStructureTool, I got this structure:

Document structure for example html

It seems that there are some issues for structuring inside .

Is there some way to get correct title attribute?

Was it helpful?

Solution

I see a trick for this problem, knowing the limitations of HTMLDocument. Try to replace your outer spans by fonts like :

    This is <font title="t2" style="color: #00FF00;">new <span style="color: #0000FF;">more</span> title</font> test

I'm pretty sure it will work. Give these font a specific class. This way you can revert them to span when exporting the html content.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top