Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the SWT Button to pressed state programmatically?

I am trying to set a SWT Button into a "pressed" state programmatically. Is that possible somehow?

Update:
What I am trying to achieve - is render draw a Button in it's selected state onto an Image.

Image buttonimg_mouseover = new Image(getDisplay(), 100, 100);
Button button = new Button(parent.parent, SWT.PUSH);
button.setAlignment(SWT.CENTER);
button.setImage(arrowimg);
button.setSize(100, 100);
button.setSelection(true); // doesn't work

GC gcbutton = new GC(buttonimg_mouseover); //draw an image of the button
button.print(gcbutton);
like image 776
Skip Avatar asked Feb 18 '23 13:02

Skip


1 Answers

You can do it with the following snippet

Button myButton = new Button(parent, SWT.TOGGLE);
myButton.setSelection(true);

However, this will only work with the types CHECK, RADIO or TOGGLE.

See Javadoc of Button#setSelection(boolean).

like image 193
Tom Seidel Avatar answered Mar 03 '23 03:03

Tom Seidel