问题描述
我们正在一个项目中遇到一个问题,即在同一JFrame上包含两个以上的Panel.我们想要的是一个Panel高于另一个Panel.
We are working on a project where we encountered a problem with including more than two Panels on the same JFrame .What we want is one Panel above the other.
社区可以帮忙举一个例子来实现这一点,还是让我参考与我们的Java Swing需求相关的优秀教程或指南?
Can the community help give an example of ho to implement this or refer me to a good tutorial or guide related to our Java Swing needs?
推荐答案
假设您要将两个面板添加到一个框架中:
Assuming you want two panels added to a single frame:
为父JFrame设置布局,并添加两个面板.类似于以下内容
Set a layout for your parent JFrame and add the two panels. Something like the following
JFrame frame = new JFrame();
//frame.setLayout(); - Set any layout here, default will be the form layout
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
frame.add(panel1);
frame.add(panel2);
假设您要在另一个面板上添加一个面板
Assuming you want to add one panel over the other
JFrame frame = new JFrame();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
frame.add(panel1);
panel1.add(panel2);
在JFrame上添加面板的数量没有限制.您应该了解,从更高的层次看,它们都是容器.
There is no limit on the number of panels to be added on the JFrame. You should understand that they all are containers when seen on a higher level.
这篇关于在一个JFrame中包括两个以上的面板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!