使用 MiGLayout 设置 JPanel 的大小
我正在使用 MiGLayout 创建几个不同的 JPanel,但是在调整其中一个的大小时遇到问题。下图显示了我想要实现的目标:
-------------------------------------------------------
| |
| Panel 1 |
| |
-------------------------------------------------------
--------------------------- ---------------------------
| | | |
| Panel 2 | | Panel 3 |
| | | |
--------------------------- ---------------------------
我想要实现的关键是使面板 1 分布在其他两个面板上。我似乎已经实现了这种布局,但是我遇到了一个问题,即面板 1 的边框没有显示,如图所示。我尝试过使用 setSize 方法,但似乎不起作用。
这是我用来创建面板的代码(请注意,我没有在面板内包含小部件):
// Create Panel 1
JPanel panelOne = new JPanel();
panelone.setSize(600, 50);
panelOne.setBorder(BorderFactory.createTitledBorder("Panel 1"));
panelOne.setLayout(new MigLayout());
// Create Panel 2
JPanel panelTwo = new JPanel();
panelTwo.setBorder(BorderFactory.createTitledBorder("Panel 2"));
panelTwo.setLayout(new MigLayout());
// Create Panel 3
JPanel panelThree = new JPanel();
panelThree.setBorder(BorderFactory.createTitledBorder("Panel 3"));
panelThree.setLayout(new MigLayout());
// Add the panels to the main frame
mainFrame.add(panelOne, "span, wrap, align center");
mainFrame.add.add(panelTwo);
mainFrame.add.add(panelThree);
请问有人可以建议一种方法来让边框显示在我的图表中吗?
I'm using the MiGLayout to create several different JPanels, however I'm having a problem resizing one of them. Below is a diagram showing what I want to achieve:
-------------------------------------------------------
| |
| Panel 1 |
| |
-------------------------------------------------------
--------------------------- ---------------------------
| | | |
| Panel 2 | | Panel 3 |
| | | |
--------------------------- ---------------------------
The key thing I want to achieve is to make Panel 1 spread across the two other panels. I seem to have achieved this layout, however I've got an issue such that the border isn't showing up for Panel 1 as shown in my diagram. I have tried using the setSize
method but it didn't seem to work.
Here is the code I'm using to create the panels (please note I haven't included the widgets inside the panel):
// Create Panel 1
JPanel panelOne = new JPanel();
panelone.setSize(600, 50);
panelOne.setBorder(BorderFactory.createTitledBorder("Panel 1"));
panelOne.setLayout(new MigLayout());
// Create Panel 2
JPanel panelTwo = new JPanel();
panelTwo.setBorder(BorderFactory.createTitledBorder("Panel 2"));
panelTwo.setLayout(new MigLayout());
// Create Panel 3
JPanel panelThree = new JPanel();
panelThree.setBorder(BorderFactory.createTitledBorder("Panel 3"));
panelThree.setLayout(new MigLayout());
// Add the panels to the main frame
mainFrame.add(panelOne, "span, wrap, align center");
mainFrame.add.add(panelTwo);
mainFrame.add.add(panelThree);
Please can someone suggest a way to get the border to be shown as in my diagram?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
另外,确保将 GUI 元素添加到主框架的内容窗格而不是框架本身。
编辑来自以下评论:
您还可以使用 new CC.wrap() 或 new CC.dockNorth()
感谢@Andrew Thompson 和@Howard 的提示:)
Try this:
Also, ensure you are adding your GUI elements to the main frame's content pane not to the frame itself.
EDIT From the comments below:
You can also use
new CC.wrap()
ornew CC.dockNorth()
Thanks to @Andrew Thompson and @Howard for the tip :)
我从未使用过该布局,但布局通常更可能尊重(强制)首选尺寸而不是尺寸。
I've never used that layout, but layouts in general are more likely to respect (enforce) the preferred size than the size.