0

I have researched thoroughly on this problem but no use. Hopefully you guys can help me. Thanks very much in advance!

The test code is below:

import javax.swing.JOptionPane;
public class JOptionPane_Test {
    public static void main(String[] args){
        String userExit="a";
        while (userExit!=null){
            userExit = JOptionPane.showInputDialog(null, "Message");
        }
    }
}

It simply displays an input box waiting for user's response, repeats if user hits OK, and stops if user hits Cancel or X button. The box halts after a random number of hitting OK (or Enter Key). It only shows the frame of the box, with the X button, and nothing inside (no message, no input field, no ok or cancel button). The only thing I can do is hitting the X button to exit out of the program.

It happens with both showMessageDialog and showInputDialog.

My log shows this warning:

!SESSION 2013-07-09 14:00:12.666 ----------------------------------------------- eclipse.buildId=4.3.0.I20130605-2000 java.version=1.7.0_25 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US Framework arguments: -product org.eclipse.epp.package.standard.product Command-line arguments: -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.standard.product

!ENTRY org.eclipse.egit.ui 2 0 2013-07-09 14:00:30.147 !MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in this system level configuration. The Git installation location can be configured on the Team > Git > Configuration preference page's 'System Settings' tab. This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.

but I suspect that this warning does not have anything to do with the JOptionPane error. Or am I wrong?

I found on this forum that someone had exactly the same problem I have, and the solution was to check on the compiler that Eclipse uses, making sure it's Sun's instead of GCJ. However, mine has always been Sun's, java 7.

I have tried both Eclipse for 64 and 32 bit.

Any help is much appreciated!!

Ut My
  • 1

1 Answers1

0

I found the solution!!! Thanks to Nick Instead of using a null parent component, I add my panes to a frame, and everything worked! It's apparently a JOptionpane bug.

Reworked code:

import javax.swing.*;

public class JOptionPane_Test {
    public static void main(String[] args){
        String userExit="a";
        JFrame frame = new JFrame();
        while (userExit!=null){
            userExit = JOptionPane.showInputDialog(frame, "Message");
        }
    }
}
Ut My
  • 1