2009-08-29 11 views

Répondre

2

Non, pas autant que je sache. Les info-bulles sont étroitement couplées aux infobulles du système natif sous-jacent, vous êtes donc bloqué avec leur comportement.

Mais il y a un autre moyen, vous devez implémenter les info-bulles vous-même. Avec cette approche, vous pouvez créer des infobulles très complexes.

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

Vous pouvez utiliser les éléments suivants:

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

Ensuite, chaque fois que vous voulez montrer, utilisez tip.setVisible(true) et commencer une minuterie, qui fera appel tip.setVisible(false) après un certain temps.

tip.setAutoHide(false) force la pointe à rester jusqu'à ce que vous appelez tip.setVisible(false).

5

J'utilise quelque chose comme ci-dessous. Merci à @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); 
        } 
       }); 
      } 
     }); 
    } 
} 

Exemple d'utilisation: SwtUtils.tooltip(button, "Text", "Message");