简体   繁体   中英

How to make a JLabel clickable?

I want to customize a JLable to make him clickable, i'm not talking about adding an Action Listener because i already have, i'm talking about changing the mouse cursor's reaction when the JLabel gain Focus just like the reaction of a mouse hoover on a link in the browser.

在此输入图像描述

I have impression that is not possible with swing.

怎么样:

label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

Swing APIs have a way of doing it:

label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

and when you change your mind:

label.setCursor(Cursor.getDefaultCursor());

I have impression that is not possible with swing.

Or maybe you just haven't yet learned how to do this perhaps? A MouseListener and MouseMotionListener have worked great for me.

Edit: and setting the JLabel's curser as noted by Max -- 1+ up-vote for him!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM