GWT

Examples on GWT

Extends popupPanel to create Tooltip

package com.javagwt.gwt.client;
(This can be vary according to your package structure.)

import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.core.client.*;

public class GWTClient implements EntryPoint{
public void onModuleLoad() {
Label label = new Label();
label.setText(“label with tooltip”);



label.addMouseListener(new MouseListenerAdapter() {
public void onMouseEnter(Widget sender) {
ToolTip tip = new ToolTip(“this is a tooltip.”,0,0);

}
public void onMouseLeave(Widget sender) {
}
public void onMouseDown(Widget sender, int x, int y) {
}
public void onMouseUp(Widget sender, int x, int y) {
}
});

RootPanel.get().add(label);
}
}
class ToolTip extends PopupPanel{

final int VISIBLE_DELAY = 2000;

Timer removeDelay;

public ToolTip(String message, int x, int y){
super(true);
this.setPopupPosition(x, y);
this.add(new Label(message));

removeDelay = new Timer(){
public void run() {
ToolTip.this.setVisible(false);
ToolTip.this.hide();
}
};
removeDelay.schedule(VISIBLE_DELAY);
this.addPopupListener(new PopupListener(){
public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
removeDelay.cancel();
}
});
this.setStyleName(“toolTip”);
this.show();
}

public boolean onEventPreview(Event event){
int type = DOM.eventGetType(event);
switch(type){
case Event.ONMOUSEDOWN:
case Event.ONCLICK:{
this.hide();
return true;
}
}
return false;
}
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s