Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JToolTips: Manually Showing, Hiding and Specifying The Position

694 views
Skip to first unread message

Darren Link

unread,
Nov 18, 2002, 10:46:08 AM11/18/02
to
Hi,

I have a JEditorPane and wish to display a tooltip whenever the cursor is
within a specific region of the document. I want the tooltip to remain
visible until the cursor is moved outside of the specific region. I do not
want the tooltip to automatically disappear after a certain amount of time.
I also need to be able to specify the exact position of the tool tip.

Can anyone explain how to use tooltips in this non-standard way?

Thanks for your help

Darren


Linda Radecke

unread,
Nov 18, 2002, 11:10:40 AM11/18/02
to

Darren Link wrote:

> Hi,

There are some methods in ToolTipManager you can use, e.g if
you need the tooltip to stay a particular amount of time there
is ToolTipManager.setDismissDelay(millis) you can use.

ToolTipManager ttm = ToolTipManager.sharedInstance();

ttm.setDismissDelay(millis); // your value

And there is getToolTipLocation() inherited from JComponent
you can override:

public Point getToolTipLocation(MouseEvent e) {
return new Point(x, y); // x, y are your values
}


Hope this is what you're looking for.


Linda
--
(=)
/ li...@jalice.ch - http://www.jalice.net
(=)

Darren Link

unread,
Nov 18, 2002, 12:30:54 PM11/18/02
to
Thanks for your help,

I had a look at the ToolTipManager but it seems to be designed for managing
tool tips when the mouse is moved over a particular component. I don't want
a tool tip to be displayed when the mouse is moved over my JEditorPane but
when a specific event occurs instead.

How for example would you create a button that shows its tool tip when its
clicked upon rather than when the mouse is moved over it?

Thanks

Darren


"Linda Radecke" <li...@jalice.ch> wrote in message
news:3DD91100...@jalice.ch...

Linda Radecke

unread,
Nov 18, 2002, 1:50:59 PM11/18/02
to

Darren Link wrote:
> I had a look at the ToolTipManager but it seems to be designed for managing
> tool tips when the mouse is moved over a particular component. I don't want
> a tool tip to be displayed when the mouse is moved over my JEditorPane but
> when a specific event occurs instead.
>
> How for example would you create a button that shows its tool tip when its
> clicked upon rather than when the mouse is moved over it?

Darren,

I wouldn't, I think :-). You mean so set the tooltip in mouseClicked
or actionPerformed of an event-handler then, perhaps? Recently there
was a thead with respect to tooltips in this forum, too on subject:
[how to force the visualization of the tooltip]. Hope this helps


Linda
--
_
/\_\Everything should be made as simple as possible,
\/_/but not simpler.* - * - * - * - *Albert Einstein

Darren Link

unread,
Nov 18, 2002, 5:32:54 PM11/18/02
to
I saw that post but unfortunately it didn't help me with my problem.

Darren

"Linda Radecke" <li...@jalice.ch> wrote in message

news:3DD93693...@jalice.ch...

Shane Petroff

unread,
Nov 18, 2002, 9:38:04 PM11/18/02
to

I would simply not use tooltips. If you have used IDEA, what you are
describing sounds similar to Alt+Q. I have not looked into how IntelliJ
have done it, but I presume they simply use a JWindow and adorn it with
colours and text which makes it look like a tooltip.

--
Shane

Kleopatra

unread,
Nov 19, 2002, 5:20:51 AM11/19/02
to

Darren Link wrote:
>
> I had a look at the ToolTipManager but it seems to be designed for managing
> tool tips when the mouse is moved over a particular component.

that's correct.

> I don't want
> a tool tip to be displayed when the mouse is moved over my JEditorPane but
> when a specific event occurs instead.

then you have to implement your own managing class that shows the
tooltip on that event (and hides it sometime later). Simply get the
JToolTip from your JEditor, set it with the appropriate text, add it to
a JPopupMenu and show the popup at any point you want to, something like

JToolTip toolTip = target.createToolTip();
toolTip.setTipText(target.getToolTipText());
JPopupMenu popup = new JPopupMenu();
// make sure we have no border
popup.setBorderPainted(false);
popup.add(toolTip);
popup.show(target, someX, someY);


Greetings
Jeanette

Darren Link

unread,
Nov 19, 2002, 10:15:45 AM11/19/02
to
Thanks,

I have tried this and I am unsure why it is working.

The API documentation states that the add method of a JPopupMenu should take
a JMenuItem. A JToolTip is not a JMenuItem and I'm confused about why it is
getting past the compiler.

The content of my tool tip needs to change whilst it is being displayed.
I've almost got this working but occassionally the JPopuMenu fails to resize
to the same size of the tool tip.

Any ideas?

Thanks

Darren

"Kleopatra" <fast...@web.de> wrote in message
news:3DDA1083...@web.de...

Kleopatra

unread,
Nov 19, 2002, 10:32:39 AM11/19/02
to

Darren Link wrote:
>
> The API documentation states that the add method of a JPopupMenu should take
> a JMenuItem. A JToolTip is not a JMenuItem and I'm confused about why it is
> getting past the compiler.

where did you read that? A JPopupMenu is just a JComponent that can cope
with special JComponents (like JMenuItems). It's used in other ways
though (see BasicComboBoxUI - which uses it for the dropdown)

>
> The content of my tool tip needs to change whilst it is being displayed.
> I've almost got this working but occassionally the JPopuMenu fails to resize
> to the same size of the tool tip.

can't reproduce it (should be okay) - but you can try to pack() the
popup after changing the content.

Greetings
Jeanette

Darren Link

unread,
Nov 19, 2002, 11:43:56 AM11/19/02
to
Sorry, I didn't have my brain switched on. I failed to check the add
methods inheritted from the java.awt.Container class.

I tried the pack method but that causes a horrible flicker when the tool tip
text is changed.

Thanks

Darren


"Kleopatra" <fast...@web.de> wrote in message

news:3DDA5997...@web.de...

Kleopatra

unread,
Nov 19, 2002, 4:56:32 PM11/19/02
to

Darren Link wrote:
>
> Sorry, I didn't have my brain switched on. I failed to check the add
> methods inheritted from the java.awt.Container class.
>
> I tried the pack method but that causes a horrible flicker when the tool tip
> text is changed.

hmm, then I'm out of ideas...

Greetings
Jeanette

0 new messages