I have a JTextField that listens to mouseevents and fetches information from a database and displays it nicely in a JToolTip (By using html).
The problem is this:
If I have many entries comming back from the database the tootip keeps going outside the screen. I would like it to add a scrollbar (similar to IntelliJ's ctrl+Q feature) so the user can scroll throught the entries....
Could be that I am using the wrong technique here...
Bumb on the question. I am trying to do this exactly. It should be possible. I would even be ok with using another component altogether to display the tool tip contents which is wrapped in a scroll pane or something to that effect. It would have to follow HTML conventions though because I use a long string with <br> points to space the data well.
Has anyone done this before? This was the only thing I could find searching on google.
doable? probably, but the best way to get a solution is for you to post a working example
of the problem you have. That way, people here can copy/paste/compile/run/observe/tinker,
and they might come up with a solution.
the working program just has to be the bare bones, include nothing unrelated to the problem.
no db stuff, just hard-coded data, which can be the same word/sentence repeated in a loop
Joined: Mar 30, 2012
I found an example that extends a JToolTip and displays a textArea inside of a scrollpane and shows that instead of the normal tool tip. I modified it a little so that it uses a JTextPane instead because I needed it to accept html so that i could have <br> statements saved in the component's .setToolTipText method.
Some drawbacks are: 1.) You have to increase the setDismissDelay value so that users have time to scroll the tool tip contents longer than the default time allowed. I set it to 15000 ms so that it gives users ample time to scroll. The drawback is that changing the code will do this to all tool tips in your project. You can't do it to just one frame (that I know of). The code for this was:
2.) You must manually specify the size of the scroll pane which holds the text pane when you create the component that will show the custom tool tip. This looks bad when you don't have enough data to fill the textpane yet you still have a fixed size textpane.
3.) You can not easily change the font of the JTextPane.
4.) You can not select text from the JTextPane to copy/paste it elsewhere.
The custom tool tip class:
Joined: Jun 09, 2003
> because I needed it to accept html so that i could have br statements saved in the component's .setToolTipText method.
I'm assuming the html and br's were used because tooltips wouldn't process \n's.
if so, textAreas are fine for \n's
Joined: Mar 30, 2012
That's true I could have went with a text area but the text pane allows me to make some text bold and it makes the tooltip look nicer.