I am trying to create a panel that can dynamically insert components based on events. The panel is row based with variable amount of components per row. However, I have problems inserting components between existing ones.
For example, if I have following layout (lines represent MigLayout cells) :
+----+----+----+
| X1 | X2 | X3 |
+----+----+----+----+
| Y1 | Y2 | Y3 | Y4 |
+----+----+----+----+
Is it possible to create a cell between rows X and Y, to get:
+----+----+----+
| X1 | X2 | X3 |
+----+----+----+
| Z1 |
+----+----+----+----+
| Y1 | Y2 | Y3 | Y4 |
+----+----+----+----+
I tried content.add(component, "cell 1 0, wrap"); but it inserts the component into the Y1 cell.
The only solution I have so far is to call content.add(component, "wrap", index);. However, this requires that I know a total count of preceding components.
Instead of using the “cell” concept, you could use “absolute” positioning for your cells in migLayout, and glue the cells together by referencing the coordinates of the neighbouring cells. You need to give names to your cells in order to reference them in migLayout.
Then, you can re-arrange the cells at any time by altering the name-references in the coordinates of the cells, you just need to call setComponentConstraints(…) for the affected cells.
f.i. you for insertige cell Z, you
See the miglayout demo application.
some code might look like:
and so on.
When you insert cell “Z”,
you only need to change the y reference of Y1 from X1.y2 to Z.y2.
I did sth. similar to create a kind of multi-splitpane, and it seems to work well.