Domanda

I created an OptionDialog without any buttons and put a JPanel in it that uses MigLayout for its layout. That JPanel has another JPanel inside of it.

Both of these panels seem to have a margin on the outside of it. Maybe it is padding on the container. Either way I would like a way to get rid of them.

How can I get rid of these margins? In the picture they are the grey and the dark orange borders around the JPanels.

JPanel

Here is the panel code:

setBackground(new Color(239,209,59));
setLayout(new MigLayout("wrap 1"));
JLabel title = new JLabel("Enroll Today!", JLabel.CENTER);
Font f = title.getFont().deriveFont((float)36);
title.setFont(f);
add(title);
JPanel docsPanel = new JPanel();
docsPanel.setBorder(BorderFactory.createEmptyBorder());
docsPanel.setLayout(new MigLayout("wrap 1", "", "[grow,fill]"));
docsPanel.setBackground(new Color(255,235,115));
for (final Document d : docs){
    JButton doc = new JButton("* "+d.getName());
    doc.setFont(f.deriveFont((float)24));
    doc.setBorder(null);
    doc.setContentAreaFilled(false);
docsPanel.add(doc);
}
add(docsPanel);

Here is the OptionDialog code:

DocumentPanel panel = new DocumentPanel(controller.getDocuments());
JOptionPane.showOptionDialog(null, panel, "Enroll now!", JOptionPane.DEFAULT_OPTION, 
                             JOptionPane.PLAIN_MESSAGE, null, new Object[] {}, null);
È stato utile?

Soluzione

Blindly, try "ins 0, wrap 1" in the MigLayout constructor.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top