Java swing JMenuBar有时候不会显示出来 [英] Java swing JMenuBar sometimes doesn't show up

查看:163
本文介绍了Java swing JMenuBar有时候不会显示出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Java桌面应用程序,有时我的jmenubar会显示出来,有时则不会。当它没有整个程序冻结,我必须杀死它。

I am working on a Java desktop application, and sometimes my jmenubar shows up, sometimes it doesn't. When it doesn't the entire program freezes and I have to kill it.

我正在创建它并在框架的构造函数中设置它。

I am creating it and setting it in my constructor for the frame.

代码:


    // Load any settings we might have made from last time.
    loadSettings();

    menuBar = createMenuBar();
    setJMenuBar(menuBar);    

    // re-evaluate and re-layout things, since they've been changed.
    validate();


    addWindowListener(this);    

正如您在我的代码中看到的,我添加了一个validate()调用,希望这会有所帮助。实际上,确实如此,但问题仍然时有发生。

As you can see in my code, I added a validate() call, hoping that would help. It does, actually, but the problem still happens from time to time.

提前感谢您的帮助!

推荐答案

基本规则如下:


  1. 验证全部 GUI元素构建在事件派发线程上。

  1. Verify that all GUI elements are constructed on the event dispatch thread.

确认吞下 no 例外情况,特别是在事件派发线程

Verify that no exceptions are swallowed, especially on the event dispatch thread.

请注意,抛出异常后,EDT将自动重启。根据具体情况,应用程序可能会冻结。虽然应该在控制台上看到某些内容,但文章 未捕获的异常处理程序 可能会提供一些见解。

Note that the EDT will restart itself after an exception is thrown. Depending on the circumstances, the application may appear to freeze. Although you should see something on the console, the article Uncaught Exception Handlers may offer some insight.

这篇关于Java swing JMenuBar有时候不会显示出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆