0

Is there a way to set cursor (hand/pointer) to JCheckbox while mouse is over it (hover)?

Martin Ille
  • 6,747
  • 9
  • 44
  • 63

1 Answers1

2

You need to set it by setCursor method. Example:

import java.awt.Cursor;
import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class sample20 {

    public static void main(String args[]) {

        JPanel wnd = new JPanel(new FlowLayout(FlowLayout.LEFT));

        JCheckBox checkbox = new JCheckBox("label");
        checkbox.setCursor(new Cursor(Cursor.HAND_CURSOR)); // this is what you need
        wnd.add(checkbox);

        JFrame frame = new JFrame();
        frame.setSize(500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(wnd);

        frame.setVisible(true);
    }
}
Martin Ille
  • 6,747
  • 9
  • 44
  • 63
  • 1+ for the setCursor() method. Don't forget that the class name should start with an upper case character. – camickr Apr 29 '15 at 18:40