Can I add an action listener to a JLabel?

后端 未结 4 1413
小鲜肉
小鲜肉 2021-02-05 09:59

I want to replace a JButton by a JLabel and I want my code to perform some action when the JLabel is clicked.

When I had the JButton I used action listener to handle cli

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 10:42

    /*add a mouselistener instead and listen to mouse clicks*/
        jlable.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        System.out.println("Yay you clicked me");
                    }
    
                });
    

提交回复
热议问题