2009-08-29 2 views
1

SWT의 툴팁 지연을 변경할 수 있습니까? 스윙에서 보통 Tooltip.sharedInstance() 메서드를 사용합니다. 이것은 SWT에서 깨는 것 같습니다.SWT 툴팁 지연 설정

답변

2

아니오, 아는만큼 멀지 않았습니다. 툴팁은 기본 네이티브 시스템의 툴팁에 단단히 결합되어있어 자신의 행동에 매달 리게됩니다.

하지만 다른 방법이 있습니다. 직접 툴팁을 구현해야합니다. 이 방법을 사용하면 매우 복잡한 툴팁을 만들 수 있습니다. 그런 다음

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

, 당신은 지정된 시간 후에 tip.setVisible(false)를 호출 타이머를, 보여 tip.setVisible(true)을 사용하고 시작할 때마다 :

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

는 다음을 사용할 수 있습니다.

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