title: Spany 2 with MigLayout with one row
body: <p>Abstract:
  I want to let one component span two rows, although there is only one row available. The following screenshots will illustrate my problem. You will find a SSCCE at the end to test things out if you want to.</p>
  
  <p>I have come along with a workaround, but I want to know if there is any better solution for this.</p>
  
  <hr>
  
  <h2>Case 1</h2>
  
  <p>There are two rows created, because enough elements have been added:<br>
  <img src="https://i.stack.imgur.com/srfKe.png" alt="Enough rows"></p>
  
  <p>Relevant code:</p>
  
  <pre><code>JPanel panel = new JPanel(new MigLayout("wrap 7, debug, fill", "grow, fill", "grow, fill"));
  int n = 8;
  for(int i=0; i&lt;n; i++) {
      JPanel p = new JPanel();
      p.setBackground(new Color(rand.nextInt()));
      if(i == 2) {
          panel.add(p, "spany 2");
      }
      else {
          panel.add(p, "");
      }
  }
  </code></pre>
  
  <p>So when the 8th panel is added, MigLayout automatically wraps it and there are two rows. Now the 3rd panel can span two rows.</p>
  
  <h2>Case 2</h2>
  
  <p>There is only one row:<br>
  <img src="https://i.stack.imgur.com/uxXJB.png" alt="Not enough rows"></p>
  
  <p>Relevant code change:</p>
  
  <pre><code>int n = 7;
  </code></pre>
  
  <p>So the row is filled with 7 panels, but MigLayout doesn't wrap to a new row and then the 3rd panel cannot span two rows.</p>
  
  <h2>Case 3</h2>
  
  <p>This is my workaround:<br>
  <img src="https://i.stack.imgur.com/M0JOO.png" alt="Workaround">    </p>
  
  <p>Relevant code change:</p>
  
  <pre><code>JPanel panel = new JPanel(new MigLayout("wrap 7, debug, fill", "grow, fill", "[grow, fill][grow, fill]"));
  </code></pre>
  
  <p>So I kinda tell MigLayout that there are two rows and so the 3rd element can span two rows. The problem is that I don't know how many rows there will be (or let's say it is inconvenient to compute it)</p>
  
  <p><strong>Is there any other possibility to achive this? My goal is to dynamically enlarge single panels to their double heigth.</strong></p>
  
  <hr>
  
  <p>SSCCE:</p>
  
  <pre><code>public class MigPositionTest {
  
      public static void main(String[] args) {
          new MigPositionTest(); //Yes it is not started within EventDispatcher
      }
  
      private Random rand = new Random(123);
  
      public MigPositionTest() {
          JFrame frame = new JFrame();
          frame.setTitle("MigLayout Span Testing");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(300, 200);
          frame.setLocationRelativeTo(null);
  
          JPanel panel = new JPanel(new MigLayout("wrap 7, debug, fill", "grow, fill", "grow, fill"));
  
          int n = 8;
  
          for(int i=0; i&lt;n; i++) {
              JPanel p = new JPanel();
              p.setBackground(new Color(rand.nextInt()));
  
              if(i == 2) {
                  panel.add(p, "spany 2");
              }
              else {
                  panel.add(p, "");
              }
  
          }
  
          frame.setContentPane(panel);
          frame.setVisible(true);
      }
  
  }
  </code></pre>