Je GridLayout
explorées avec, BorderLayout
et GridBagLayout
et je crois que tout espace vertical supplémentaire qui est présent dans votre application est en raison de la taille du composant JCheckBox, non lié au gestionnaire de mise en page. Tous les exemples ci-dessous n'ont pas d'espace entre les composants dans le gestionnaire de disposition.
GridLayout
//Changing to 3,1,1,0 makes slightly smaller (1 pixel) gap vertically
GridLayout layout = new GridLayout(3, 1, 1, 0);
JPanel main = new JPanel(layout);
main.add(new JCheckBox("box 1"));
main.add(new JCheckBox("box 2"));
main.add(new JCheckBox("box 3"));
GridBagLayout
GridBagConstraints gbc = new GridBagConstraints();
JPanel main = new JPanel(new GridBagLayout());
gbc.gridx=0;
gbc.gridy=0;
gbc.ipady=0;
main.add(new JCheckBox("box 1"), gbc);
gbc.gridy=1;
main.add(new JCheckBox("box 2"), gbc);
gbc.gridy=2;
main.add(new JCheckBox("box 3"), gbc);
BorderLayout
JPanel main = new JPanel(new BorderLayout());
main.add(new JCheckBox("box 1"), BorderLayout.NORTH);
main.add(new JCheckBox("box 2"), BorderLayout.CENTER);
main.add(new JCheckBox("box 3"), BorderLayout.SOUTH);