tags:

views:

24

answers:

1
JPanel panel = new JPanel(null);
panel.setSize(400, 400);
panel.add(new JButton("Test"));
panel.setCursor(Cursor.getCursor(Cursor.SOMETHING_SOMETHING_CURSOR));

The panel will have a custom cursor, but I don't want the button to have a custom cursor. I don't want to have to set the cursor of every sub component, because in my application I have many and I don't want to litter the code with setCursor statements.

Is there a way, like overriding a method on the JPanel or something? A "contains" method somewhere is used to determine if a cursor needs to be set. Could I fool it into thinking the mouse is not in the container if it's really in a sub component? Any other nifty little trick?

+1  A: 

Could I fool it into thinking the mouse is not in the container if it's really in a sub component?

Maybe on your panel you can use a MouseListener. On mouseEntered you set your cursor. On mouseExited, you set the cursor to null.

camickr