Search code examples
javahtmlswinghyperlinkjeditorpane

Formatting JEditorPane's cursor, tooltips, links


Right now, I'm using Java Swing to create a JEditorPane primarily for its ability to have hyperlinks. I've successfully been able to display links and have them execute behavior upon a click, but I'm running into a few problems with formatting.

  1. How can I set the cursor so that it normally is an arrow, but changes to a text cursor when hovering over text? (In essence, the behavior a cursor has within a web browser). I tried

    EditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR))
    

    but that made it a text cursor everywhere, even when not hovering over text. Right now, hovering over a link shows a pointer hand; I'd like to maintain that functionality as well.

  2. What is the best way to show tooltips or mouseover text when hovering over a link? I tried modifying the title attribute of the link but nothing showed up.

  3. I was trying to implement links to skip down to a subsection of the page, much like http://en.wikipedia.org/wiki/Xkcd#History would take you directly to the History subsection of Wikipedia's xkcd page. How can I do this?

An answer to any of these would be great (and multiple would be awesome xP). Thanks a lot for your help!


Solution

  • As you said one can simply give answers to a single point as well, let me try one by one, here is the answer for your last Point 3

    Just provide an id to your tag like this

    <h1><a id = "top"></a>First Line</h1>
    

    Now somewhere in the bottom of your page write this :

    <p><a href = "#top">Return to TOP</a></p>
    

    Clicking this link, you will reach the above area of the PAGE.