问题
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.
回答1:
how to show them center of container?
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.
回答2:
- GroupLayout
provides a hassle free way arranging the components as you want them too.
- GroupLayout
was developed by NetBeans
Group in 2005.
- You can download the Windows Builder Pro
for free from Google, and use it.
来源:https://stackoverflow.com/questions/12768592/adding-panel-in-center-of-container