The visible state of a control may change depending on the visible state of its parent control, how do I know this?
For example
Display display = Display.getDefault() ;
Shell shell = new Shell( display ) ;
shell.setSize( 400, 600 ) ;
shell.setLayout( new FillLayout( SWT.VERTICAL ) ) ;
Composite composite = new Composite( shell, SWT.NONE ) ;
composite.setLayout( new FillLayout() ) ;
Button test = new Button( composite, SWT.NONE ) ;
test.setText( "test" ) ;
composite.addListener( SWT.Show, e -> System.out.println( "Composite Show" ) ) ;
composite.addListener( SWT.Hide, e -> System.out.println( "Composite Hide" ) ) ;
test.addListener( SWT.Show, e -> System.out.println( "Button Show" ) ) ;
test.addListener( SWT.Hide, e -> System.out.println( "Button Hide" ) ) ;
Button btn = new Button( shell, SWT.TOGGLE ) ;
btn.setText( "Show / Hide" ) ;
btn.addListener( SWT.Selection, e -> {
composite.setVisible( btn.getSelection() ) ;
System.out.println( test.isVisible() ) ;
} ) ;
shell.open() ;
while ( !shell.isDisposed() ) {
if ( !display.readAndDispatch() ) {
display.sleep() ;
}
}
I can’t get the Button’s Show/Hide event.