4

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

I display a modal dialog and set the cursor of the main frame on "waiting state". Everything is fine, except that if the mouse exits the main frame and enters again, it never comes back on "waiting state". This bug (?) doesn't happen if the dialog is not modal.

The test 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);
    }
General Grievance
  • 4,555
  • 31
  • 31
  • 45
paranoia25
  • 626
  • 1
  • 5
  • 23

1 Answers1

2

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

  • Cursor is possibe to change (or change is visible) for window that have got focus, this is basic properties for Modal window or for ModalityTypes,

it never comes back on "waiting state". This bug (?) doesn't happen if the dialog is not modal.

  • after child JDialog is closed, then JFrame could be changed Cursor to WAIT_CURSOR

  • you to visible the changed Cursor by removing setModal() or to change changing ModalityTypes to the ModalityType.MODELESS

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Ok, thx, I don't know that! The problem is that I want add a progress bar in the modal dialog and make the cursor waiting in the entire application until the dialog disappears. How can I dot that ? – paranoia25 Oct 04 '12 at 09:40
  • @paranoia25 have (move logics) to change Cursor for popup window (JDialog in your case), let it JFrame .... :-), [could be hard job for newbee, possible lack on EDT](http://stackoverflow.com/questions/12108127/getting-the-cancel-event-of-java-progressmonitor/12108209#12108209), have search on this forum SwingWorker and JProgressBar, ... daily answered similair question – mKorbel Oct 04 '12 at 12:33