Reputation: 2120
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");
}
}
Upvotes: 1
Views: 8205
Reputation: 12817
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.
Upvotes: 0
Reputation: 1
Use something like
new MigLayout("", "0[]0[]0[]0", "[]");
this.add(left, "gapx 0 0");
this.add(center, "gapx 0 0");
Upvotes: 0
Reputation: 755
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.
Upvotes: 4