【发布时间】:2017-02-26 21:55:37
【问题描述】:
我目前正在使用此代码:
this.getContentPane().add(wwjPanel, BorderLayout.EAST);
if (includeLayerPanel)
{
this.controlPanel = new JPanel();
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
this.layerPanel = new LayerPanel(this.getWwd());
this.controlPanel.add(new FlatWorldPanel(this.getWwd()),Box.createRigidArea(new Dimension(1000, 1000))); //This is the top pan
this.controlPanel.add(this.getStates(), Box.createRigidArea(new Dimension(0, 100)));
this.controlPanel.add(this.getPanelAlerts(), Box.createRigidArea(new Dimension(0,100)));
this.getContentPane().add(this.controlPanel, BorderLayout.WEST);//This is the whole panel on the left
}
我正在尝试调整 JPanel(此处称为 controlPanel)的大小,以使每个 JPanel 在我的 GUI 中都有自己独特的大小。我是使用 java 构建 GUI 的新手,我拥有的大部分代码都是从另一个文件中提取的。我试图合并的代码是我的代码中描述的这些新面板,并试图调整它们的大小。我想要使用 BoxLayout 来获得想要的效果吗?
此外,当我使用 createRigidArea 时,它似乎可以工作,但如果我继续更改您传递给它的 x 和 y 值,似乎什么也没有发生。我的意思是,通过更改值我看不到任何视觉差异,并且我使用的值范围为 0-1000。
谢谢。
【问题讨论】:
标签: java swing jpanel layout-manager boxlayout