Java 8, Swing, and OSX: Dialogs make the user interface inactive for the mouse

Okay, so this is a really, REALLY weird problem that we have with the application in my company. I will try to describe it as best as possible.

Firstly, it is an obsolete Swing user interface application.

Secondly, the problem only occurs when it is compiled and launched using Java 8. This does not happen with Java 7 and below.

So, the problem is: when the dialog is displayed (modal or non-modal, it does not matter), the user interface becomes immune to mouse clicks. However, what is really crazy is that the user interface is NOT frozen. Hovering over something causes the cursor to highlight as usual. Keyboard commands are great. However, mouse clicks do not work.

This also happens only on OSX. Windows and Linux do not have this problem. I am running this on OSX El Capitan.

For code samples, this affects all dialogs in the application. JOptionPanes and JDialogs don't seem to matter. Here is a simple JOptionPane declaration:

int n = JOptionPane.showOptionDialog(mcContext.getMapperView(), "xPath of dropping target can't be evaluated" + "\nPlease, select xPath for dropped node", "xPath calculation for dropped node", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); 

This code is called in EventThread, so I do not consider this a problem with threads.

I am completely fixated on the reason for this. So far, we have ignored it, compiling and running it in Java 7, but at some point, when the versions will evolve, we will have to solve this problem more directly.

Does anyone have any idea?

Edit: Thanks for the idea of ​​SSCCE. Now I'm more confused than ever. When I put together a quick frame / dialog demo, it worked perfectly. No questions. Therefore, I do not know what exactly in the application can cause this. Any good places to start looking?

Edit 2: One of the ads in SwingUtilities.invokeLater was wrapped and it worked. Alright ... now, what could be the culprit? This should still be something that Java 8 compiles other than Java 7.

Edit 3: Stranger behavior. I moved my IDE to a separate "desktop" than the application in which it was running, and when the error dialog is displayed, I cannot switch to this desktop. I can switch to any application on the current desktop, but not to another desktop.

Edit 4: These dialogs are launched using drag and drop actions. Not sure if this helps or not, but I see that there is a stream in the background in the stream dump using the sun.lwawt.macosx.CDragSourceContextPeer class.

+8
java swing macos
source share
1 answer

Well, it took a while, but I think I found it. I found an OpenJDK post that seemed to describe this issue very clearly.

https://bugs.openjdk.java.net/browse/JDK-8139393

Be that as it may, Drag N Drop in Swing on OSX in java 8 does not release it from being held on MouseEvent or Listener, therefore, when a modal dialog is displayed, the mouse cannot receive new events to it. This is a crazy stupid mistake, but it is there.

The solution was to wrap my code in SwingUtilities.invokeLater (...). With code that displays dialogs that are executed asynchronously using the drag and drop code, the drag and drop operation can complete and release the commit when the mouse is connected (due to lack of a better description). And viola! The problem is resolved.

Thanks to everyone who tried to help. Hope this post helps anyone else solve this problem.

+2
source share

All Articles