MigLayout 50% 宽度

发布于 2025-01-07 10:13:40 字数 566 浏览 0 评论 0原文

我有一个面板,它是 JDialog 的 contentPane。该面板水平分为两部分。 UpperHalfPanelLowerHalfPanel 通过:

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

LowerHalfPanel 垂直分为两部分。 LowerHalfLeftPanelLowerHalfRightPanel

现在 UpperHalfPanel 的大小由 JTextField 的列数决定,我正在寻找一种方法来制作 LowerHalfLeftPanelLowerHalfRightPanel 填充 LowerHalfPanel 宽度的 50%。

简而言之,它可以被描述为一个有两行的表格,底行有两个相等的列。

I have a Panel which is a contentPane of a JDialog. That Panel is divided horizontally into two parts. UpperHalfPanel and LowerHalfPanel by:

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

The LowerHalfPanel is divided vertically into two parts. LowerHalfLeftPanel and LowerHalfRightPanel.

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.

Briefly it can be described as a Table with two row and the bottom row has two equal column.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不气馁 2025-01-14 10:13:40

也许您正在寻找分割/跨度。如果没有更多代码示例,很难说。很多时候我发现 MigLayout 使得嵌套面板变得不必要。如果您想出一个简单的简短示例,甚至是模拟图像,都会有所帮助。

听起来你想要这样:

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);

这将使上部面板跨越 2 个“单元格”,并且根据这些面板的内容,左下角和右下角在其下方均匀划分。有一些方法可以强制大小,例如“!”或“wmin”。尝试 swing 演示,转到跨度部分。右键单击这些区域将让您尝试这些限制。另请参阅 MigLayout 备忘单

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. 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. There are ways to force the size, such as the "!" or "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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文