2009-08-29 75 views

回答

2

不,據我所知。工具提示與底層本地系統的工具提示緊密結合,因此您堅持了自己的行爲。

但還有另一種方法,你將不得不自己實現工具提示。用這種方法你可以創建非常複雜的工具提示。

class TooltipHandler { 
    Shell tipShell; 

    public TooltipHandler(Shell parent) { 
     tipShell = new Shell(parent, SWT.TOOL | SWT.ON_TOP); 

     <your components> 

     tipShell.pack(); 
     tipShell.setVisible(false); 
    } 

    public void showTooltip(int x, int y) { 
     tipShell.setLocation(x, y); 
     tipShell.setVisible(true); 
    } 

    public void hideTooltip() { 
     tipShell.setVisible(false); 
    } 
} 
3

您可以使用下列內容:

ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION); 
tip.setText("Title"); 
tip.setMessage("Message"); 
tip.setAutoHide(false); 

然後,每當你要顯示它,使用tip.setVisible(true)和啓動一個定時器,在指定的時間後會調用tip.setVisible(false)

tip.setAutoHide(false)強制提示留下,直到您致電tip.setVisible(false)

5

我使用類似下面的東西。由於@Baz :)

public class SwtUtils { 

    final static int TOOLTIP_HIDE_DELAY = 300; // 0.3s 
    final static int TOOLTIP_SHOW_DELAY = 1000; // 1.0s 

    public static void tooltip(final Control c, String tooltipText, String tooltipMessage) { 

     final ToolTip tip = new ToolTip(c.getShell(), SWT.BALLOON); 
     tip.setText(tooltipText); 
     tip.setMessage(tooltipMessage); 
     tip.setAutoHide(false); 

     c.addListener(SWT.MouseHover, new Listener() { 
      public void handleEvent(Event event) { 
       tip.getDisplay().timerExec(TOOLTIP_SHOW_DELAY, new Runnable() { 
        public void run() { 
         tip.setVisible(true); 
        } 
       });    
      } 
     }); 

     c.addListener(SWT.MouseExit, new Listener() { 
      public void handleEvent(Event event) { 
       tip.getDisplay().timerExec(TOOLTIP_HIDE_DELAY, new Runnable() { 
        public void run() { 
         tip.setVisible(false); 
        } 
       }); 
      } 
     }); 
    } 
} 

用例:SwtUtils.tooltip(button, "Text", "Message");