如何在Java中设置更多面板

发布于 2024-08-25 23:36:25 字数 184 浏览 7 评论 0原文

我需要将两个 JPanel 放入一个 JApplet 中。

paneel = new RekenmachinePaneel();
nummer = new NummerPaneel();
setContentPane(paneel);

现在我需要让数字面板显示在面板下方。我该怎么做呢?

I need to get two JPanels into one JApplet.

paneel = new RekenmachinePaneel();
nummer = new NummerPaneel();
setContentPane(paneel);

Now I need to get the nummer panel to show up beneath the paneel. How should I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沧桑㈠ 2024-09-01 23:36:25

如果您想添加两个面板,则必须创建第三个面板:

JPanel myPanel = new JPanel();
myPanel.add(paneel);
myPanel.add(nummer);
setContentPane(myPanel);

如果您想获取特定组件内的面板数量,请使用以下命令:

int no = yourComponent.getComponents().length;

If you want to add both panels you will have to create a third one:

JPanel myPanel = new JPanel();
myPanel.add(paneel);
myPanel.add(nummer);
setContentPane(myPanel);

If you want to get the number of panels you have inside an specific component use this:

int no = yourComponent.getComponents().length;
盗琴音 2024-09-01 23:36:25

您可以使用布局来定位它们。

setLayout(new GridLayout(0,1));
add(paneel);
add(nummer);

You can use a layout to position them.

setLayout(new GridLayout(0,1));
add(paneel);
add(nummer);
凉城已无爱 2024-09-01 23:36:25

将布局设置为空。

paneel.setLayout(null);
nummer.setLayout(null);

通过将布局设置为空,您可以将任何面板移动到任何面板上。但不建议这样做,因为您不会使用布局的功能(表单、边框、框等)。

此外,您还需要正确定位面板的位置。

paneel.setLocation(x2,y2);
nummer.setLocation(x1,y1);

Make the layout as null.

paneel.setLayout(null);
nummer.setLayout(null);

By setting the layouts to null, you can move any panels over any panel. But its not recommended as you will not be using the power of layouts (form, border, box etc.,)

Also you would need to the location of the panels properly.

paneel.setLocation(x2,y2);
nummer.setLocation(x1,y1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文