在容器中心添加面板 [英] Adding panel in center of container

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

问题描述

我有 JPanel 这是一个 BorderLayout ,我在顶部和容器中设置了一个新面板( JDesktopPane )位于中心,另一个面板位于底部。现在我想在容器中心动态设置面板(卡片布局),因为我在下面显示层次结构

I have a JPanel which is a BorderLayout and I have set a new panel in the top and container (JDesktopPane) in center and another panel in bottom. Now I want to set panel (card layout) dynamically in center of container as I am showing hierarchy below

           top --> panel
panel(BorderLayout)center --> container(JDesktopPane) --> panel(CardLayout)
            bottom --> panel

此处卡片布局包含不同的面板作为卡片。问题是我无法在容器中心显示每张卡。

Here card layout contain different panel as card. problem is that I'm unable to show each card in center of container.

推荐答案


如何显示它们的容器中心?

how to show them center of container?

将它们放在一个带有 GridBagLayout 的面板中,将它们添加为唯一没有约束的组件,它们将居中。有关示例,请参见此答案

Put them in a panel with a GridBagLayout, add them as the only component with no constraint, and they will be centered. See this answer for an example.

这篇关于在容器中心添加面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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