title: Java layout when using JScrollPane
body: <p>This is my code</p>
  
  <pre><code>private static KeyEvent e;
  private static String text1 = null;
  private static String text = null;
  
    public fysikdel() {
      super("Fysikformler");
      setSize(700, 502);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      init();
      setResizable(true);
      setVisible(true);
    }
  
    public void init() {
      JPanel main = new JPanel();
      JPanel p = new JPanel();
      CardLayout c1 = new CardLayout();
  
      JScrollPane scrollpane = new JScrollPane(p);
  
      JPanel Mekanik = new JPanel();
      p.setSize(700, 502);
      Mekanik.setLayout(new FlowLayout());
  
      //637*237
      ImageIcon likformigrorelsei = new ImageIcon();
      JLabel likformigrorelsel = new JLabel();
  
      ImageIcon lagesenergii = new ImageIcon();
      JLabel lagesenergil = new JLabel();
  
      ImageIcon a = new ImageIcon();
      JLabel aa = new JLabel();
  
      ImageIcon b = new ImageIcon();
      JLabel bb = new JLabel();
  
      try {
          likformigrorelsei = new ImageIcon(new URL("http://i.imgur.com/TZFkXYa.jpg"));
      } catch (MalformedURLException e1) {
          e1.printStackTrace();
      }
      likformigrorelsel.setIcon(likformigrorelsei);
  
      try {
          lagesenergii = new ImageIcon(new URL("http://i.imgur.com/TZFkXYa.jpg"));
      } catch (MalformedURLException e1) {
          e1.printStackTrace();
      }
      lagesenergil.setIcon(lagesenergii);
  
      try {
          a = new ImageIcon(new URL("http://i.imgur.com/TZFkXYa.jpg"));
      } catch (MalformedURLException e1) {
          e1.printStackTrace();
      }
  
      aa.setIcon(a);
  
      try {
          b = new ImageIcon(new URL("http://i.imgur.com/TZFkXYa.jpg"));
      } catch (MalformedURLException e1) {
          e1.printStackTrace();
      }
  
      bb.setIcon(b);
  
      Mekanik.add(likformigrorelsel);
      Mekanik.add(lagesenergil);
      Mekanik.add(aa);
      Mekanik.add(bb);
  
      JPanel Tryck = new JPanel();
  
      main.setLayout(new GridLayout(1,1));
      p.setLayout(c1);
  
      this.add(main);
  
      main.add(scrollpane);
  
      p.add(Mekanik, "1");
      p.add(Tryck, "2");
      c1.show(p, "1");
  </code></pre>
  
  <p>When I add more pictures I want them to fill up from left to right untill one row is filled, then fill the next row. At the moment it just continue to fill the first row. </p>
  
  <p>If I add       </p>
  
  <pre><code> scrollpane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); 
  </code></pre>
  
  <p>it just removes the horizontal scroll bar but the pictures are still ending up on one row.</p>
  
  <p>I dont know what is wrong. Thanks for any help!</p>