문제

I'm writing a Java desktop application, running Ubuntu 10.10. Everything works fine except that about 1 in 10 times, when I call JOptionPane.showMessageDialog(null, message), the dialog window appears but it is empty -- just the standard gray background. Strangely, a few times when this has happened I have been able to click where the OK button should have been and it registered the click fine. Does anyone know what could cause this?

도움이 되었습니까?

해결책

Which JVM are you using? Make sure it's not GCJ (as it often is by default Ubuntu/Debian). It's swing implementation is a little odd and will often elicit strange behavior like that.

다른 팁

Are you displaying the dialog from the Event Dispatch Thread? Strange bugs with symptons like this might occur from time to time if Swings single thread rule is violated.

I subscribe to Uhlen's post. The most probable cause is that you might not use Event Dispatch Thread for Swing code. Example:

try {
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            JOptionPane.showConfirmDialog(null, "Message");
        }
    });
} catch (InterruptedException ex) {

} catch (InvocationTargetException ex) {

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top