Setting the SWT Button to pressed state programmatically?

自作多情 提交于 2019-12-23 12:59:45

问题


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);

回答1:


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).



来源:https://stackoverflow.com/questions/13308066/setting-the-swt-button-to-pressed-state-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!