javaswinglayoutlayout-managermiglayout

Vertical button bar layout using miglayout


I'm wondering about the "best" way to achieve a relatively usual layout with mig layout. I have large components (say, JLists in this case), and buttons between the two large components. So I want a vertical button stack, with a gap at the bottom. I have done it a couple of time, but

  1. there seems to be a lot of ways to achieve this result ;
  2. each time, I proceeded by trial and errors, and I feel I must miss something.
  3. in any case, as this is a rather usual problem, it would be nice to have a sample somewhere, and stackOverflow seems to be used as the MigLayout wiki.

So, I want to achieve this presentation with miglayout :

+---------------+  +----+  +----------------------+
|  list 1       |  | bt1|  |  list2               |
|               |  +----+  |                      |
|               |  +----+  |                      |
|               |  | bt2|  |                      |
|               |  +----+  |                      |
|               |  +----+  |                      |
|               |  | bt3|  |                      |
|               |  +----+  |                      |
|               |          |                      |
|               |          |                      |
+---------------+          +----------------------+

Currently, I do :

add(new JScrollPane(jlist1),"grow, pushy");
add(button1,"flowy, aligny top, split 3");
add(button2, "");
add(button3, "");
add(new JScrollPane(jlist2), "grow, pushy");        

Are there better ways to do it? Is it worthwhile to avoid creating a panel for putting the buttons in it?


Solution

  • I would just put the buttons in their own panel. That simplifies the layout and similar components tend to get modified together so it is good to have them in their separate function or class.

    Whenever possible I try to use a tree-like structure of containers rather than have a complicated layout that includes all the components. It makes it harder to read and rearrange things when everything depends on the layout of everything else.