我在GWT应用程序中使用GXT的Info类来显示消息或通知。为了使消息更有粘性,我实现了我自己版本的Info类:我创建了一个InfoConfig
实例并设置毫秒数:config.display(int milliseconds);
问题是有时我不需要信息是"粘",所以我需要隐藏它,当我做别的事情:我试图调用hide()
方法,但它不工作!
我的Info类实现:
public class StickyInfo extends Info {
private static StickyInfo info = new StickyInfo();
public StickyInfo() {
super();
}
@Override
protected void onShowInfo() {
super.onShowInfo();
}
/**
* Show the message with a title for 20sec (default duration)
*
* @param title
* the title of the message.
* @param message
* the message to display.
*/
public void show(String title, String message) {
show(title, message, 20000); // for 20sec
}
/**
* Show the message with no title for 20sec (default duration)
*
* @param message
* the message to display.
*/
public void show(String message) {
show(null, message, 20000); // for 20sec
}
/**
* Show the message for the specified number of milliseconds.
*
* @param title
* the title of the message.
* @param message
* the message to display.
* @param milliseconds
* the number of milliseconds to display the message.
*/
public void show(String title, String message, int milliseconds) {
// Configuration
InfoConfig config = new DefaultInfoConfig(title, message);
config.setDisplay(milliseconds);
// Formatting
info.setStyleName("background-color:#f9ff4f;text-align:center;"
+ "border:0x solid black; padding: 3px; font-size:11px;font-weight: bold;");
info.show(config);
// Position
// Point p = info.position();
// p.setY(p.getY() + 400);
// p.setX(0);
info.setPagePosition(info.position().getX(), 55);
}
/**
* Show the message in the given position for the number of milliseconds.
*
* @param title
* the title of the message.
* @param message
* the message to display.
* @param milliseconds
* the number of milliseconds to display the message.
*/
public void show(String title, String message, int milliseconds, int pX,
int pY) {
// Configuration
InfoConfig config = new DefaultInfoConfig(title, message);
config.setDisplay(milliseconds);
// Formatting
info.setStyleName("background-color:#f9ff4f;text-align:center;"
+ "border:0x solid black; padding: 3px; font-size:11px;font-weight: bold;");
info.show(config);
// Position
// Point p = info.position();
// p.setY(p.getY() + 400);
// p.setX(0);
info.setPagePosition(pX, pY);
}
指针吗?谢谢。
尝试@Override隐藏()方法div…
正如user2043260所提到的,我试图用以下方法覆盖hide()
方法:
@Override
public void hide() {
if (info.getParent != null) {
info.removeFromParent();
}
}
它工作得很好:)!谢谢你的提醒;)