title: Java Swing BoxLayout: Adjusting space between panels in a multi-panel setup?
body: <p>I'm writing this swing application and I'm using multiple panels in a BoxLayout format, but it seems to be that the empty space between the panels is being divided up between them and it looks really ugly. How do you adjust and customize how much space is put between panels? Sorry if this is a repost; I was unable to find an older post.</p>
  <pre><code>    import java.awt.*;
  import java.awt.datatransfer.Clipboard;
  import java.awt.datatransfer.StringSelection;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.*;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  
  class gui extends JFrame implements ActionListener{
      JFrame frame = new JFrame(&quot;Ark Admin Spawn Commands&quot;);
      JPanel panel = new JPanel();
      JComboBox dinos;
      JComboBox corruptedDinos;
      public JSlider dinoLevel;
      JLabel input;
      JLabel dino;
      JLabel title;
      
      
      
      
      
      gui(){
          
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
            JPanel mainPanel = new JPanel();
            mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
  
            JPanel panelOne = new JPanel();
            JPanel panelTwo = new JPanel();
            JPanel panelThree = new JPanel();
  
            mainPanel.add(panelOne);
            mainPanel.add(panelTwo);
            mainPanel.add(panelThree);
           
          
          
          
          title = new JLabel(&quot;Spawning Dinos&quot;);
          
          String[] dinoNames= {&quot;The Island:&quot;};
          String[] corruptedDinoNames = {&quot;Extinction:&quot;};
          dinos = new JComboBox(dinoNames);
          corruptedDinos = new JComboBox(corruptedDinoNames);
          dinoLevel = new JSlider(JSlider.HORIZONTAL, 1, 600, 400);
          dinoLevel.setMajorTickSpacing(20);
          dinoLevel.setPaintTicks(true);
          input = new JLabel(&quot;Select Level: &quot;);
          event e = new event();
          dinoLevel.addChangeListener(e);
          
          
          dinos.addActionListener(this);
          corruptedDinos.addActionListener(this);
          panelOne.add(title);
          
          panelTwo.add(input);
          panelTwo.add(dinoLevel);
          
          panelThree.add(dinos);
          panelThree.add(corruptedDinos);
          this.getContentPane().add(mainPanel);
          this.setTitle(&quot;Ark Admin Spawn Commands&quot;);
          this.setSize(600, 600);
          this.setVisible(true);
          
      }
      public static void main (String args[]) {
  
          new gui();
          
          
      
      
      }
      
      public class event implements ChangeListener{
          
          @Override
          public void stateChanged(ChangeEvent e) {
              int value = dinoLevel.getValue();
              input.setText(&quot;Level: &quot; + value);
              
          }
      }
      
      @Override
      public void actionPerformed(ActionEvent arg0) {
          
          
      }
  }
  </code></pre>