我有一个小问题,我使用MigLayout开始了一个新的图形用户界面项目,我喜欢它的布局,但有一件事我想不通,那就是如何消除组件本身、组件和框架之间的间隙以及单元格和行之间的间隙
现在MigLayout文档描述了使用"gap 0px 0px“,其中gap gapx我确实在两个轴上将gap设置为0px,但差距仍然存在。有人可以帮帮忙吗?他们的论坛是一个鬼城:)
我想要消除JPanels和JFrame之间的差距。红色框和框架边框,并且我想删除红色JPanel中的填充。我的代码如下:

package pe.view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import net.miginfocom.swing.MigLayout;
public class UI_View extends JFrame
{
//Content panels
private JPanel left = new JPanel(new MigLayout());
private JPanel center = new JPanel(new MigLayout());
private JPanel right = new JPanel(new MigLayout());
//Content components
private DefaultListModel list_content = new DefaultListModel();
private JList list = new JList(list_content);
public UI_View()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setMinimumSize(new Dimension(800, 600));
this.setTitle("PropriarityEnvoirment");
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setLayout(new MigLayout("gap 0px 0px"));
String data[] = {"Hi","Hello","WiWi","Hello","WiWi","Hello","WiWi","Hello","WiWi","Hello","WiWi","Hello","WiWi","Hello","WiWi","Hello","WiWi","Hello","WiWi"};
for(int i = 0; i < data.length; i++)
{
list_content.addElement(data[i]);
}
left.add(list);
left.setBackground(Color.red);
center.setBackground(Color.green);
right.setBackground(Color.blue);
this.add(left, "growy, pushy");
this.add(center, "grow, pushx");
this.add(right, "grow, pushy");
}
}发布于 2011-12-30 14:03:05
要在BorderLayout中删除容器之间的空格,可以使用类似于miglayout的Docking。
通过停靠,您的代码将如下所示:
...
this.setLayout(new MigLayout());
...
left.add(list, "dock north");
...
this.add(left, "dock west");
this.add(center, "dock center");
this.add(right, "dock east");
...我希望这能帮到你。
发布于 2012-01-10 20:36:13
使用像这样的东西
new MigLayout("", "0[]0[]0[]0", "[]");
this.add(left, "gapx 0 0");
this.add(center, "gapx 0 0");发布于 2017-02-16 23:28:13
我今天也找到了它,在布局约束中设置insets可以解决它。
panel.setLayout(new MigLayout("insets 0 0 0 0, fill, debug", "", ""));如果我们不将其设置为0,则会设置默认大小并且很大,就像您在项目中看到的那样。
https://stackoverflow.com/questions/8674691
复制相似问题