I tried the following and it worked fine, also after displaying another JDialog
(on Windows, JDK 1.6.0_12).
Mouse cursor changes every 50 pixels in horizontal direction, clicking the JPanel
opens a modal JDialog
. Close it again and mouse cursor still changes.
public class DialogCursorTest extends JDialog{
public DialogCursorTest() {
final JPanel panel = new JPanel();
panel.addMouseMotionListener(new MouseMotionAdapter() {
Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
@Override
public void mouseMoved(MouseEvent e) {
if(e.getX() % 100 > 50) {
if(panel.getCursor() != handCursor) {
panel.setCursor(handCursor);
}
}
else {
if(panel.getCursor() == handCursor) {
panel.setCursor(Cursor.getDefaultCursor());
}
}
}
});
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
new JDialog(DialogCursorTest.this, "Test", true).setVisible(true);
}
});
getContentPane().add(panel);
}
public static void main(String[] args) {
DialogCursorTest test = new DialogCursorTest();
test.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
test.setSize(400, 300);
test.setVisible(true);
}
}