首页 > 解决方案 > 如何使用 MigLayout 在 java swing 中制作聊天(whatsapp 之类)ui

问题描述

我想向 MigLayout 添加组件,我可以将其添加为发送/接收的消息,就像这样:

--------------------------------------------
| received message                         |

|                              sent Message|
--------------------------------------------

我创建了以下构造函数:

new MigLayout(
        // set the automatic wrap after columns
        "insets 0, wrap 0", 
        // hardcode fixed column width and fixed column gap 
        "", 
        // hardcode fixed height and a zero row gap
        "[]10"));

在添加组件时,如果我使用“推,好吧”它为我完成了这项工作,但组件占用了平均高度空间,如下面的链接所示:

在此处输入图像描述

所以我想要的只是这些组件一个接一个,在构造函数中只指定了间隙(10)。谢谢

标签: javaswinglayout-managermiglayout

解决方案


尝试类似:

JPanel parent = JPanel( new BorderLayout() );
parent.add(yourPanelUsingMigLayout, BorderLayout.PAGE_START);
frame.add(parent);

BorderLayout.PAGE_START 将尊重组件的首选高度。因此,您不应该看到组件之间的垂直空间。


推荐阅读