[英]Is there any other way to add an ActionListener to a button using windowbuilder (eclipse) in design mode than to double click on the button?
我是 eclipse 的 windowbuilder 设计师的新手。 我正在使用 eclipse 2021-12、jdk 17 和 windowbuilder 1.9.8 版本。 我正在尝试在设计模式下的按钮上添加 actionListener。 但是当我在设计模式下双击这个按钮来添加一个 actionListener 时,什么也没有发生。
这是我在源代码模式下的源代码:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Color;
public class SwingApp {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SwingApp window = new SwingApp();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public SwingApp() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnClick = new JButton("Click");
btnClick.setBackground(new Color(219, 112, 147));
btnClick.setForeground(new Color(255, 255, 255));
btnClick.setFont(new Font("Inconsolata SemiBold", Font.BOLD, 14));
btnClick.setBounds(165, 101, 118, 51);
frame.getContentPane().add(btnClick);
}
}
这是设计模式下的渲染:设计模式下的渲染
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.