0

I want create a JFrame in java with some Text in that. In my text, some of words need to be explained, so I want to do this: For example if my text is: "Obama is president in USA", I want if the cursor is on "Obama" a tool-tip open and explain about Obama, the meaning of words are stored in a file and I can search it for.

I want (if it is possible) the cursor change to hand and the the tool-tip appear, also if user click on that, full meaning of that word appear in JTextArea or something like that.

In the end, I want if words in my text has meaning in my file, the color of word change to blue.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
HsnFirooz
  • 57
  • 4
  • 2
    please whats wrong with [question asked here](http://stackoverflow.com/search?tab=newest&q=[java]%20[swing]%20tooltip) and description in official Oracle tutorial [How to use Tooltips](http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html) voting to close – mKorbel Jan 09 '14 at 10:55
  • possible duplicate of [Text-mouseover popups over a Swing JTextArea?](http://stackoverflow.com/questions/5957241/text-mouseover-popups-over-a-swing-jtextarea) – Ceiling Gecko Jan 09 '14 at 10:58
  • You have our permission to 'Go for it!'. Since you failed to ask a question, I'm voting to close as 'too broad'. – Andrew Thompson Jan 09 '14 at 11:52

1 Answers1

3

You need to create custom TextArea and override the getToolTipText(MouseEvent) method

public class CustomToolTipArea extends JTextArea {
  public String getToolTipText(MouseEvent event) {
    int pos = viewToModel(event.getPoint());
    // calculate vord at Position in text and determine the tooltip text for the word.
  }
}
Sergiy Medvynskyy
  • 11,160
  • 1
  • 32
  • 48