我有一个小问题,我使用 MigLayout 开始了一个新的 GUI 项目,我喜欢这种布局,但我无法弄清楚的一件事是如何消除组件本身、组件和框架之间的所有间隙以及单元格和行之间的间隙
现在 MigLayout 文档描述了使用“gap 0px 0px”,其中间隙 [gapx] [gapy] 我确实在两个轴上都将间隙设置为 0px,但间隙仍然存在,有人可以在这里帮忙,他们的论坛是一座鬼城 :)
我想删除 JPanel 和 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");
}
}