Modal dialog box prevents correct cursor state

I have a problem with displaying a modal dialog and a busy cursor at the same time.

I show a modal dialog box and set the cursor of the main frame in the "idle state". Everything is in order, except that if the mouse exits the main frame and enters again, it never returns to the standby state. This error (?) Does not occur if the dialog is not modal.

Testing program:

public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setSize(new Dimension(500, 500)); final JDialog dialog = new JDialog(frame); dialog.setModal(true); frame.add(new JButton(new AbstractAction("Dialog") { @Override public void actionPerformed(ActionEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); dialog.setVisible(true); } })); frame.setVisible(true); } 
+4
source share
1 answer

frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

  • Cursor possible to change (or change the view) for the window that received focus , these are the main properties for the Modal window or for ModalityType s,

he never returns to a waiting state. This error (?) Does not occur if the dialog is not modal.

  • after the child JDialog closed, then the JFrame can change Cursor to WAIT_CURSOR

  • you see the visible Cursor by deleting setModal() or changing the ModalityType change to ModalityType.MODELESS

+2
source

Source: https://habr.com/ru/post/1437760/


All Articles