0

I have a custom widget (a Group that contains other Composites) that looks like the top image:

I want to implement the behavior that when the user double-clicks on "some text", the widget collapses to something like the bottom image.

If "some text" is double-clicked again, then the widget expands to the original version.

I could implement this by destroying/creating the other widgets inside the green rectangle (i.e., the small text, the rounded rectangle and the circle) and then calling pack() on the green rectangle upon double-click, but I was wondering if there is a more elegant coding idiom for implementing the described behavior? Note: I do not want to use a widget with a designated toggle-button (e.g., a PGroup).

1 Answer 1

1

If you use GridLayout with GridData on each item you can use:

(GridData)data = (GridData)control.getLayoutData();

data.exclude = true;

control.setVisible(false);

to hide a control, when all controls are hidden use layout() on the parent composite. To show again reverse the exclude and setVisible calls.

3
  • Thanks, Greg! This is quite elegant. Is there any way I can decrease the size of the rounded rectangle and circle (they are Image objects), without having to destroy the originals and recreate them with smaller-sized images?
    – Steph
    Feb 14, 2014 at 21:08
  • Not sure what you mean by Image object in this context. You could use a Label with setImage and just switch between two images.
    – greg-449
    Feb 14, 2014 at 21:37
  • This works, Greg. I used a similar approach -- a Canvas on which I draw images of different size, depending on whether the widget is in the expanded or the collapsed state. I was just wondering if there is an existing SWT method, e.g., "zoom in/out" that one can use with a single image, instead of swapping different images.
    – Steph
    Feb 17, 2014 at 2:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.