2009-08-29 102 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");