cheerpj-appletrunner icon indicating copy to clipboard operation
cheerpj-appletrunner copied to clipboard

setModalityType() not yet supported

Open ghost opened this issue 6 years ago • 7 comments

This is a follow up issue to the issue here: https://github.com/leaningtech/cheerpj-appletrunner/issues/16#issuecomment-455589518

I just noticed that modal dialogs are not fully modal. I can still interact with the menu bar of the applet. As a result I can open the same modal dialog multiple times. Here I open it the first time:

unbenannt

ghost avatar Jan 18 '19 15:01 ghost

Now I can still interact with the menu of the applet, and can open the modal dialog a second time:

about_interaction

ghost avatar Jan 18 '19 15:01 ghost

The second modal dialog opens on top of the present modal dialog:

unbenannt2

ghost avatar Jan 18 '19 15:01 ghost

Usually for modal dialogs, the menus are blocked. It is even so that Swing does a "beep", when I try to click into the menus.

BTW: I am using advanced Swing API to set the dialog to modal. The advanced Swing API allows different sub modes of modal. My code contains the following API call before making it visible:

        setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
        setVisible(true);

I use the advanced Swing API for some requirements for when the code runs not from within a single applet, but when I have multiple windows. Hold on, let me also test the traditional API.

ghost avatar Jan 18 '19 15:01 ghost

Intersting I changed the code to the following:

        setModal(true);
//        setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
        setVisible(true);

And now the menu is blocked. Oki Doki. So the advanced API is not yet working for applets. I can workaround my code accordingly.

ghost avatar Jan 18 '19 15:01 ghost

Hi @jburse , thanks for your report!

How did you create the JDialog? If you didn't specify the parent, Dialog.ModalityType.DOCUMENT_MODAL is not enough to prevent clicking on the applet. You should use something like :

setModalityType(Dialog.ModalityType.APPLICATION_MODAL);

(Which should be equivalent to your workaround of setModal(true))

Can you provide us a test case showing different behaviour between CheerpJ and native Java (leaving aside the window stacking issue tracked in https://github.com/leaningtech/cheerpj-appletrunner/issues/31 )?

yuri91 avatar Jan 22 '19 13:01 yuri91

If you don't specify a parent, it still has a parent. At least the JDK 1.8 source tells me:

   super(owner == null? 
       SwingUtilities.getSharedOwnerFrame() : owner,
              title, modal);

As soon as I have time, I can make more testing with different modalities (there are not many).

ghost avatar Jan 22 '19 16:01 ghost

@jburse The simplest thing would be for you to revert the workaround (i.e. using setModal(true)) so that we can directly test our applet.

alexp-sssup avatar Jan 22 '19 16:01 alexp-sssup