Java-> MigLayout如何设置间隙
我有一个小问题,我使用 MigLayout 启动了一个新的 GUI 项目,我喜欢这个布局,但我不明白的一件事是如何消除组件本身、组件和框架之间的所有间隙以及单元格和行之间的间隙
现在 MigLayout 文档描述了使用“间隙 0px 0px”,其中间隙 [间隙] [间隙] 我确实在两个轴上将间隙设置为 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");
}
}
I have a small problem, i started a new GUI project using MigLayout and i love the layout but one thing i cannot figure out is how to remove all gaps between components them selves, components and frame and gap between cells and rows
Now MigLayout documentation describes using "gap 0px 0px" where gap [gapx] [gapy]
I did set gap to 0px on both axis but the gap is still there can someone help out here their forums are a ghost town : )
I want to remove the gap between JPanels and JFrame.. The red box and frame border, and
i want to remove the padding inside the red JPanel. My code is bellow:
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");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要删除 miglayout 中容器之间的空间,您可以使用
Docking
,它类似于 BorderLayout。通过对接,您的代码将如下所示:
我希望这会有所帮助。
To remove the space between a container in miglayout you can make use of
Docking
, which is similar to BorderLayout.With docking your code will look something like this:
I hope this helps.
使用类似的东西
Use something like
我今天也发现了它,并在布局约束中设置插图解决了它。
如果我们不将其设置为
0
,则默认大小将被设置并且很大,就像您在项目中看到的那样。I also found it today and setting the insets in the layout constraint solves it.
If we don't set it to
0
, the default size will be set and is huge, like what you saw in your project.