Help with problematic layout using MigLayout
I've been trying to align some objects in my java project in a certain way but with no success. I am using MigLayout for the layout and this is how I would like it to look:
- The sidebar should have a static width (220px) and be docked left.
- The right column should have a fluid width and expand according to window size.
- The footer should be docked to开发者_JAVA技巧 the bottom and have a static height, fluid width.
This is the code that I have got now:
this.setLayout(new MigLayout("fill, wrap 2", "[30%][70%]", "grow"));
this.add(sourceList, "w 30%");
this.add(listView, "w 70%");
this.add(bottomBar.getComponent(), "growx, push, span");
I've been trying to understand the usage instructions but they are hard to understand. I was hoping someone here had knowledge about working with MigLayout and could help me.
I use WindowBuilder Pro which helps very much is building these out. It's free, and supports MigLayout too.
Doing what you just described in it gets me:
setLayout(new MigLayout("", "[220][grow]", "[grow][]"));
add(sidebar, "cell 0 0,grow");
add(main, "cell 1 0,grow");
add(bottom, "cell 0 1 2 1,grow");
This keeps the sidebar at a fixed 220 (from the column spec in the constructor) and the bottom at a static height with the preferred size. The width of column 2 and height of column 1 will grow to fill, as will the components in each cell.
精彩评论