Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8, Swing, and OSX: Dialogs make UI unresponsive to Mouse

Tags:

java

macos

swing

Ok, so this is a really, REALLY weird issue that we're having with the application at my company. I'm going to try and describe this as best I can.

First, this is a legacy application with a Swing UI.

Second, the issue only occurs when it is compiled & run using Java 8. With Java 7 and below, this does not occur.

So, the issue: When a dialog is displayed (modal or non-modal, doesn't matter), the UI becomes unresponsive to mouse clicks. What's truly crazy, though, is the UI is NOT frozen. Hovering the mouse over something produces the hover highlight as normal. Keyboard commands are received perfectly. Mouse clicks, however, do not work.

This also only occurs on OSX. Windows and Linux don't have this problem. I'm running this on OSX El Capitan.

As far as code samples, it's affecting all dialogs across the application. JOptionPanes & JDialogs, doesn't seem to matter. Here's 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 being called on the EventThread, so I don't believe it's a threading issue.

I'm totally stumped as to the cause of this. So far we've ignored it by compiling and running it in Java 7, but at some point as versions progress we will need to deal with this issue more directly.

Anyone have any ideas?

Edit: Thanks for the SSCCE Idea. Now I'm more confused than ever. When I put together a quick frame/dialog demonstration, it worked perfectly. No issues. So I don't know what it is in the application that could be causing this. Any good places to start looking?

Edit 2: Wrapped one of the declarations in SwingUtilities.invokeLater, and it worked. Ok... now what could the culprit be? It's still got to be something that Java 8 is compiling different than Java 7.

Edit 3: More weird behavior. I moved my IDE into a separate "desktop" than the application it was running, and when the buggy dialog is displayed, i cant switch to that desktop. I can switch to any app on the current desktop, but not to another desktop.

Edit 4: The dialogs in question are being triggered by drag and drop actions. Not sure if that helps or not, but I do see that there is a thread in the background in the thread dump using the sun.lwawt.macosx.CDragSourceContextPeer class.

like image 961
craigmiller160 Avatar asked Mar 24 '16 17:03

craigmiller160


1 Answers

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

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

Somehow, Drag N Drop in Swing on OSX in java 8 isn't releasing its hold on the MouseEvent or Listener, so when a modal dialog is displayed the mouse isn't able to get new events through to it. Which is a crazy stupid bug, but it's there.

The solution was wrapping my code in SwingUtilities.invokeLater(...). By having the code that displays the dialogs executed asynchronously from the drag and drop code, the drag and drop operation is able to complete and release its hold on the mouse connectivity (for lack of a better description). And viola! Problem solved.

Thanks to everyone who tried to help. Hope this post helps out anyone else dealing with this issue.

like image 153
craigmiller160 Avatar answered Oct 23 '22 19:10

craigmiller160