Can I add an action listener to a JLabel?

后端 未结 4 1342
小鲜肉
小鲜肉 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:34

    Add a MouseListener to the JLabel.

    Because JLabel is a Component, you can add MouseListeners to it. Use that interface and write the mouseClicked event on your MouseListener to handle the click.

提交回复
热议问题