title: Java components being hidden in JPanel
body: <p>I have two <code>JPanels</code>, each with a bunch of <code>JButtons</code> in them. The <code>JPanel</code> containing the other two has a <code>BoxLayout</code> and the two other <code>JPanels</code> are <code>FlowLayout</code>. The problem is when the window is resized to make the buttons wrap, the buttons in the first and second panel (<code>p0</code>,<code>p2</code>) are covered up by the edge of their corresponding panels. Any ideas?</p>
  
  <p><img src="https://i.stack.imgur.com/5G7AO.png" alt="enter image description here"></p>
  
  <pre><code>import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.Rectangle;
  
  import javax.swing.BoxLayout;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.Scrollable;
  import javax.swing.border.TitledBorder;
  
  public class Test {
      public static void main(String[] args) {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JPanel p0 = new JPanel();
          p0.setLayout(new FlowLayout());
          p0.setBorder(new TitledBorder("p0"));
          JPanel p1 = new JPanel();
          p1.setLayout(new FlowLayout());
          p1.setBorder(new TitledBorder("p1"));
          CustomPanel panel = new CustomPanel();
          JScrollPane sp = new JScrollPane(panel);
          panel.add(p0);
          panel.add(p1);
          frame.add(sp);
          panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p0.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          p1.add(new JButton("Hello World!"));
          frame.setVisible(true);
      }
  
  }
  
  class CustomPanel extends JPanel implements Scrollable {
  
      @Override
      public Dimension getPreferredScrollableViewportSize() {
          return null;
      }
  
      @Override
      public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
          return 0;
      }
  
      @Override
      public boolean getScrollableTracksViewportHeight() {
          return false;
      }
  
      @Override
      public boolean getScrollableTracksViewportWidth() {
          return true;
      }
  
      @Override
      public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
          return 0;
      }
  
  }
  </code></pre>