2013-03-27 79 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