How to set hand cursor to all buttons
In nowadays web oriented world users expectations are that desktop application behave like web application.
And part of this that cursor must be changed when moving over button and checkbox controls.
Next code snippet satisfied needs:
public MainFrame{
initComponents();
setCursorToAllButtons(this);
}
private void setCursorToAllButtons(Container container) {
Component[] components = container.getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof Container){
setCursorToAllButtons((Container)components[i]);
}
if (components[i] instanceof JButton || components[i] instanceof JCheckBox) {
components[i].setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
}
No related posts.























