如何将光标指针/指针设置为JCheckbox?

时间:2015-04-29 17:36:51

标签: java jcheckbox

有没有办法在鼠标悬停时将光标(手/指针)设置到JCheckbox(悬停)?

1 个答案:

答案 0 :(得分:2)

您需要按setCursor方法进行设置。例如:

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);
    }
}