mouseover on a Hyperlink

12 views
Skip to first unread message

joster

unread,
Sep 12, 2007, 1:32:58 AM9/12/07
to Google Web Toolkit
Hi-

Is it possible to add mouseover on a Hyperlink? If so, how?

I have several Hyperlinks and would like to provide a mouse over text
(like a small tool-tip) for the hyperlink.

Thanks.
Joster

Les Harris

unread,
Sep 12, 2007, 1:39:54 AM9/12/07
to Google-We...@googlegroups.com
The Hyperlink class unfortunately does not appear to support that on
its own. However, I believe that you should look into FocusPanel.

You would put a Hyperlink into a FocusPanel and the focus panel will
receive the mouse events you are looking for and you can then do
whatever you want with them.

If you find yourself needing this sort of thing often putting together
a simple composite of the two will make your life easier!

FocusPanel docs here:
http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.FocusPanel.html

joster

unread,
Sep 12, 2007, 5:39:02 AM9/12/07
to Google Web Toolkit
Thanks Les. This helped, I made a composite (FocusPanel + Hyperlink)
to handle my case.

On Sep 11, 10:39 pm, "Les Harris" <orphean...@gmail.com> wrote:
> The Hyperlink class unfortunately does not appear to support that on
> its own. However, I believe that you should look into FocusPanel.
>
> You would put a Hyperlink into a FocusPanel and the focus panel will
> receive the mouse events you are looking for and you can then do
> whatever you want with them.
>
> If you find yourself needing this sort of thing often putting together
> a simple composite of the two will make your life easier!
>

> FocusPanel docs here:http://code.google.com/webtoolkit/documentation/com.google.gwt.user.c...

Peter Blazejewicz

unread,
Sep 12, 2007, 4:01:36 PM9/12/07
to Google Web Toolkit
hi Joster,

other solution requires just few changes in Hyperlink extended class:

public class MyHyperlink extends Hyperlink {
MyHyperlink(String text, String targetHistoryToken) {
super(text, targetHistoryToken);
sinkEvents(Event.MOUSEEVENTS);
}

public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONMOUSEOVER) {
showTips();
}
super.onBrowserEvent(event);
}

private void showTips() {
if (tip == null) {
tip = new PopupPanel(true);
tip.setWidget(new Label("Clicks me! click me!"));
tip.setStyleName("gwt-DialogBox");
}
tip.setPopupPosition(getAbsoluteLeft() + 5, getAbsoluteTop() + 5);
tip.show();
}

private PopupPanel tip;
}

RootPanel rootPanel = RootPanel.get();
Hyperlink hyperlink = new MyHyperlink("New Hyperlink", "some history
token");
rootPanel.add(hyperlink, 5, 5);

regards,
Peter

jhulford

unread,
Sep 13, 2007, 9:26:41 AM9/13/07
to Google Web Toolkit
If all you need is a simple bit of text to display, you can just set
the hyperlink's title attribute to your text. That's a very
rudimentary tooltip-like display which is often good enough for alot
of uses. If you need the event handling capability though you'll need
to follow Les or Peter's suggestion.
Reply all
Reply to author
Forward
0 new messages