gpt4 book ai didi

java - 以编程方式将 SWT 按钮设置为按下状态?

转载 作者:搜寻专家 更新时间:2023-11-01 01:45:09 26 4
gpt4 key购买 nike

我正在尝试以编程方式将 SWT 按钮设置为“按下”状态。这有可能吗?

更新:
我想要实现的目标是渲染将处于选定状态的按钮绘制到图像上。

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

最佳答案

您可以使用以下代码片段来完成

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

但是,这仅适用于 CHECKRADIOTOGGLE 类型。

参见 Button#setSelection(boolean) 的 Javadoc .

关于java - 以编程方式将 SWT 按钮设置为按下状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13308066/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com