`

定制tooltip

阅读更多
public class HelloToolTip {   
  
    public static void main(String[] args) {   
        Display display = new Display();   
        Shell shell = new Shell(display);   
        shell.setText("Hello table");   
        shell.setLayout(new RowLayout());   
        shell.setSize(300, 200);   
  
        Text text = new Text(shell, SWT.BORDER);   
        text.setToolTipText("Hello,text!");   
        
        ToolTip toolTip = new ToolTip(shell, ToolTip.NO_RECREATE, true) {

            protected Composite createToolTipContentArea(Event event, Composite parent) {
                // Create the content area
                Composite composite = new Composite(parent, SWT.NONE);
                composite.setBackground(parent.getDisplay().getSystemColor(
                        SWT.COLOR_INFO_BACKGROUND));
                Text text = new Text(composite, SWT.READ_ONLY);
                text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                text.setText("custom tooltip,text!");
                GridLayoutFactory.fillDefaults().margins(2, 2).generateLayout(composite);
                return composite;
            }
        };
//        toolTip.setHideOnMouseDown(false);
//        toolTip.setHideDelay(1000);
        toolTip.setPopupDelay(0);
        toolTip.activate();
           

           
        shell.open();   
        while(!shell.isDisposed()){   
            if(!display.readAndDispatch()){   
                display.sleep();   
            }   
        }   
        display.dispose();   
    }   
  
}  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics