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
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
(=)
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...
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
"Linda Radecke" <li...@jalice.ch> wrote in message
news:3DD93693...@jalice.ch...
--
Shane
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
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...
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
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...
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