简体   繁体   English

在我最小化或调整JFrame之前,JMenu不会出现

[英]JMenu doesn't appear until I minimize or resize the JFrame

I have a GUI with a JMenuBar , the problem is that sometimes a JMenu doesn't appear until i resize or minimize the JFrame . 我有一个带有JMenuBar的GUI,问题是有时候JMenu在我调整大小或最小化JFrame之前不会出现。 Can someone help me? 有人能帮我吗?

I had the same problem, and I solved it by setting the JFrame visible AFTER the code for the menu. 我遇到了同样的问题,我通过在菜单代码后设置JFrame来解决它。 So you first create a JFrame after that add the JMenuBar and at last: frame.setVisible(true); 所以你首先创建一个JFrame ,然后添加JMenuBar ,最后: frame.setVisible(true); (my frame is just called "frame" replace the "frame" with the name of your frame) (我的框架被称为“框架”,用框架的名称替换“框架”)

另外,比@马尔科的解决方案不太漂亮,是调用frame.revalidate()frame.setJMenuBar() -call。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM