Search code examples
javaeclipseswingjoptionpane

JOptionPane Dialog boxes not displaying correctly in Eclipse


I'm using Java 12.0.2 on Eclipse 2019-09, and recently I've come across JOptionPane dialog boxes refusing to display. I've tried with Eclipse 2019-06 but to no avail, I've tried with different file and class names, and with different eclipse-workspace locations too. Any ideas on how to fix this?

EDIT: Using the "Show Command Line" button I got this: C:\Program Files\Java\jdk-12.0.2\bin\javaw.exe -Dfile.encoding=UTF-8 -classpath "C:\Users\Michael\eclipse-workspace\test\bin" test.test

I am on Windows 10 Home, Version 1903. I forced the OpenGL rendering GPU in Nvidia control panel to my dedicated GPU but it didn't change a thing. I also added the JDK's \bin location to PATH in environment variables and set JAVA_HOME correctly too, but nothing changed.

Here's the code I used:

package test;

import javax.swing.JOptionPane;

public class test {

    public static void main(String[] args) {
        JOptionPane.showMessageDialog(null, "test");
    }

}

Which gives this result:
Image


Solution

  • Ok, so I found a "solution" of sorts. I found that the problem isn't with Eclipse, as a .jar I ran similarly only showed a white blank box and crashed, just like with JOptionPane in the image above.

    What I did was I installed the 32-bit Java 8u231 JDK, configured Eclipse to use it instead of 12.02, and bada-bing the JOptionPane window displayed correctly and didn't crash.

    The .jar I previously tried running also worked perfectly after I uninstalled JDK 12.02

    It's still a mystery as to why only the 32-bit JDK seems to work, I will continue researching and troubleshooting, but in the meanwhile, if anyone has a similar issue, here's how I (temporarily and imperfectly) solved it.

    image1

    image2

    EDIT: By re-installing windows, I was able to get the 64-bit JDK to work. Everything is back to normal, hopefully the problem doesn't arise again.