有没有办法在鼠标悬停时将光标(手/指针)设置到JCheckbox(悬停)?
答案 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);
}
}