Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

enter image description here

I have impression that is not possible with swing.

like image 255
imanis_tn Avatar asked Apr 17 '12 00:04

imanis_tn


2 Answers

How about:

label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
like image 90
tenorsax Avatar answered Nov 15 '22 06:11

tenorsax


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());
like image 40
Jakub Zaverka Avatar answered Nov 15 '22 06:11

Jakub Zaverka