简体   繁体   English

MigLayout 50%宽度

[英]MigLayout 50% width

I have a Panel which is a contentPane of a JDialog . 我有一个Panel,它是JDialog的contentPane。 That Panel is divided horizontally into two parts. 该小组将水平分为两部分。 UpperHalfPanel and LowerHalfPanel by: UpperHalfPanelLowerHalfPanel通过:

Panel.add("UpperHalfPanel", "wrap");
Panel.add("LowerHalfPanel");

The LowerHalfPanel is divided vertically into two parts. LowerHalfPanel垂直分为两部分。 LowerHalfLeftPanel and LowerHalfRightPanel . LowerHalfLeftPanelLowerHalfRightPanel

Now the size of the UpperHalfPanel is determined by number of columns of a JTextField and I am finding a way to make the LowerHalfLeftPanel and LowerHalfRightPanel fill 50% of width of LowerHalfPanel . 现在UpperHalfPanel的大小由JTextField的列数确定,我正在寻找一种方法来使LowerHalfLeftPanelLowerHalfRightPanel填充LowerHalfPanel宽度的50%。

Briefly it can be described as a Table with two row and the bottom row has two equal column. 简而言之,可以将其描述为具有两行的表,而底行具有两个相等的列。

Maybe you are looking for split/span. 也许您正在寻找拆分/跨度。 Without more of a code example, it's hard to say. 没有更多的代码示例,这很难说。 A lot of times I find that MigLayout makes nested panels unnecessary. 很多时候,我发现MigLayout使得不需要嵌套面板。 If you come up with a simple short example or even a mock image, it would help. 如果您想出一个简单的简短示例甚至是模拟图像,都将有所帮助。

It sounds like you want this: 听起来您想要这样:

JPanel outerPanel = new JPanel(new MigLayout());
JPanel upperPanel = new JPanel();
JPanel lowerLeftPanel = new JPanel();
JPanel lowerRightPanel = new JPanel();

outerPanel.add(upperPanel, "span 2, wrap");
outerPanel.add(lowerLeftPanel);
outerPanel.add(lowerRightPanel);

This will make upper panel span 2 "cells" and the lower left and right be evenly divided under it depending on the contents of those panels. 这将使上部面板跨度为2个“单元格”,并且根据这些面板的内容将其下方的左下方和右下方均匀划分。 There are ways to force the size, such as the "!" 有一些方法可以强制大小,例如“!”。 or "wmin". 或“ wmin”。 Try out the swing demo , go to the span section. 尝试挥杆演示 ,进入跨度部分。 Right clicking on the areas will let you experiment with the contraints. 右键单击这些区域可以让您尝试使用约束。 Also see the MigLayout cheat sheet . 另请参阅MigLayout 备忘单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM