Java布局中心有两个面板 [英] Java layout center with two panels

查看:701
本文介绍了Java布局中心有两个面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,当使用BorderLayout时,是否可以在CENTER中有两个面板,但两者都可以在窗体上看到。



这是我的代码:

  guiFrame.add(guiFieldsPanel,BorderLayout.CENTER); 
guiFrame.add(guiButtonsPanel,BorderLayout.CENTER);
guiFrame.setVisible(true);

在上面的代码中,两个面板都设置为中心,但我只能看到guiButtonsPanel为它位于guiFieldsPanel的顶部。



我可以将两个面板组合在一起,然后将它们设置为在CENTER中显示吗?

解决方案

有关的想法,请参阅中可以看到。 E.G。




In Java, when using the BorderLayout, is it possible to have two panels in the CENTER, but both be visible on the form.

Here is my code:

    guiFrame.add(guiFieldsPanel, BorderLayout.CENTER);
    guiFrame.add(guiButtonsPanel, BorderLayout.CENTER);        
    guiFrame.setVisible(true);

In the above code, both panels are set to the center, yet I can only see the guiButtonsPanel as it is 'on top' of the guiFieldsPanel.

Can i group both panels together, and then set them to be displayed in the CENTER?

解决方案

See the Nested Layout Example for ideas about how to combine layouts to create the required layout. E.G.

Perhaps use a single row GridLayout for the center.

guiFrame.add(guiFieldsPanel, BorderLayout.CENTER);
guiFrame.add(guiButtonsPanel, BorderLayout.CENTER);        

But that suggests a 2 column GroupLayout as seen in this answer. E.G.

这篇关于Java布局中心有两个面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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