且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使jframe中的jpanel可见

更新时间:2023-12-05 09:08:52

您的问题在这里:

setLayout(null);

使用空布局时,由编码人员完全负责所有添加组件的位置和大小.您添加的组件没有大小,因此默认为0、0.

When you use null layouts, you the coder are completely responsible for the location and size of all added components. Your added component has no size and so defaults to 0, 0.

一个(不好的)解决方案:给MenuePanel一个大小或界限

A (bad) solution: give the MenuePanel a size or bounds

一个更好的解决方案:学习和使用布局管理器(正如您最确定的搜索已经告诉您的那样).

A much better solution: learn and use the layout managers (as all your searches most assuredly already told you).