Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes JTooltip with a vertical scrollbar? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTooltip with a vertical scrollbar?" Watch "JTooltip with a vertical scrollbar?" New topic
Author

JTooltip with a vertical scrollbar?

Henrik Engert
Ranch Hand

Joined: Apr 26, 2005
Posts: 70
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...

Any suggestions?


SCJP 5.0, SCWCD
Javier Paredes
Greenhorn

Joined: Mar 30, 2012
Posts: 3
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.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Has anyone done this before?

I've not heard of this anywhere.

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
Javier Paredes
Greenhorn

Joined: Mar 30, 2012
Posts: 3
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:
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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
Javier Paredes
Greenhorn

Joined: Mar 30, 2012
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTooltip with a vertical scrollbar?