java - 如何以编程方式模拟复合背景上的按钮单击?

标签 java user-interface click swt

我需要以编程方式模拟复合背景上的按钮单击。具体来说:位于 Composite 的左上角。

最佳答案

您可以使用 Button.notifyListeners(int eventType, Event event) 来模拟 SWT 按钮单击:

final Button setButton = new Button(composite, SWT.PUSH);
setButton.setText("Set");
setButton.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(final SelectionEvent e) {
        // some code here
    }
});

MenuItem clickMenuItem = new MenuItem(testMenu, SWT.PUSH);
clickMenuItem.setText("Click");
clickMenuItem.addListener(SWT.Selection, new Listener() {
    public void handleEvent(Event event) {
        setButton.notifyListeners(SWT.Selection, new Event());
    }
});

关于java - 如何以编程方式模拟复合背景上的按钮单击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7685400/

相关文章:

python - 如何允许在 PyQt4 中调整 QMessageBox 的大小

c++ - QTextEdit删除给定位置的整行

java - JFrame.setDefaultLookAndFeelDecorated(true);

jQuery 2 个点击功能,其中一个不触发

html - 获取 Canvas 内每个矩形的点击事件?

Java JPanel getGraphics() 函数

java - 不使用用户名密码身份验证保护 servlet URL 的安全

java - Android:如何在多个图像按钮上设置监听器?

java - 使用 JSOUP Java 更改 CSS

java - 如何将日期解析为带有 am/pm 的 long 类型?