2013-03-27 94 views
0

我在我的GWT应用程序中使用GXT的Info类来显示消息或通知。为了使消息有点粘粘的,我实现了我自己的信息类的版本:我创建了一个InfoConfig实例并设置毫秒数:config.display(int milliseconds);如何隐藏GXT的信息通知?

的问题是有时我并不需要的信息是“粘“所以当我做别的事情时,我需要隐藏它:我试图调用hide()方法,但它不工作!

我实现信息类:

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); 
    } 

任何指针?谢谢。

回答

0

由于user2043260提到的,我试着用以下命令以取代hide()方法:

@Override 
public void hide() { 
    if (info.getParent != null) { 
     info.removeFromParent(); 
    } 
} 

,它工作正常:)!感谢提醒;)

2

尝试@覆盖隐藏()方法 ....

+0

谢谢,没有看到:) – amrfaissal 2013-03-28 00:04:41