Java-> MigLayout如何设置间隙

发布于 2024-12-23 13:15:28 字数 1736 浏览 0 评论 0原文

我有一个小问题,我使用 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滴情不沾 2024-12-30 13:15:28

要删除 miglayout 中容器之间的空间,您可以使用 Docking,它类似于 BorderLayout。

通过对接,您的代码将如下所示:

...
this.setLayout(new MigLayout());
...
left.add(list, "dock north");
...
this.add(left, "dock west");
this.add(center, "dock center");
this.add(right, "dock east");
...

我希望这会有所帮助。

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:

...
this.setLayout(new MigLayout());
...
left.add(list, "dock north");
...
this.add(left, "dock west");
this.add(center, "dock center");
this.add(right, "dock east");
...

I hope this helps.

拔了角的鹿 2024-12-30 13:15:28

使用类似的东西

new MigLayout("", "0[]0[]0[]0", "[]"); 
this.add(left, "gapx 0 0"); 
this.add(center, "gapx 0 0");

Use something like

new MigLayout("", "0[]0[]0[]0", "[]"); 
this.add(left, "gapx 0 0"); 
this.add(center, "gapx 0 0");
楠木可依 2024-12-30 13:15:28

我今天也发现了它,并在布局约束中设置插图解决了它。

panel.setLayout(new MigLayout("insets 0 0 0 0, fill, debug", "", ""));

如果我们不将其设置为0,则默认大小将被设置并且很大,就像您在项目中看到的那样。

I also found it today and setting the insets in the layout constraint solves it.

panel.setLayout(new MigLayout("insets 0 0 0 0, fill, debug", "", ""));

If we don't set it to 0, the default size will be set and is huge, like what you saw in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文