MigLayout 用法
对于那些熟悉 MigLayout 的人来说,这是一个问题,
抱歉想不出更合适的名称对于这个问题...
我正在尝试创建一个布局,最终看起来如下所示:
+---------+---------+
| btn1 | btn2 |
+---------+---------+
| |
| btn3 |
| |
+-------------------+
当调整窗口大小时,组件 btn1 和 btn2 应填充 x 轴(各一半),并且组件 btn3 应填充x 轴和 y 轴上的所有可用空间。
你将如何实现这一目标?
下面是一些代码:
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = window.getContentPane();
cp.setLayout(new MigLayout(""));
cp.add(new JButton("btn1"), "");
cp.add(new JButton("btn2"), "");
cp.add(new JButton("btn3"), "");
window.pack();
window.setVisible(true);
}
A question for those familiar with MigLayout
sorry couldn't think of a more appropriate name for the question...
I'm trying to create a layout that will end up looking like the following:
+---------+---------+
| btn1 | btn2 |
+---------+---------+
| |
| btn3 |
| |
+-------------------+
when the window is resized the components btn1 and btn2 should fill the x-axis (half each), and the component btn3 should fill both the x-axis and all of the available space in the y-axis.
how would you achieve this?
here's some code to start with:
public static void main(String[] args)
{
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = window.getContentPane();
cp.setLayout(new MigLayout(""));
cp.add(new JButton("btn1"), "");
cp.add(new JButton("btn2"), "");
cp.add(new JButton("btn3"), "");
window.pack();
window.setVisible(true);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在 MigLayout 中非常简单:
如果您阅读 pstanton 的原始问题,我认为所需的布局说明与他的表述方式非常接近。这就是我喜欢 MigLayout 的原因:)
This is pretty easy in MigLayout:
If you read pstanton's original question, I think the layout instructions required are very close to how he formulated it. That's what I like about MigLayout :)
我从未使用过 miglayout,但它应该类似于以下内容:
I've never used miglayout, but it should be something like the following:
那么你想要这样的东西吗:
Swing 布局演示就有它,在“Flow Direction”下面,
这是其中的代码样本:
So do you want something like this:
The very Swing Layout Demo has it, under "Flow Direction"
Here's the code from that sample: