0

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.

4
  • The Show/Hide event is only sent on the Composite. Looking at the source there is no attempt to propogate the event to its children. Commented Aug 17, 2024 at 9:35
  • Yes, but is there any other way to know the change of visible state from the child Control level? Commented Aug 18, 2024 at 7:36
  • Not that I know off, but I have never had a need to respond to visibility changes. You would have to listen to the Composite event and go though the children of the composite. Commented Aug 18, 2024 at 7:43
  • What would knowing the state of visibility, setting aside that it could be partially visible in different amounts ms to ms, let you do? Commented Aug 19, 2024 at 17:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.