MigLayout does not have such a function. It is grid-based, and although you can use the nogrid parameter to stream components horizontally or vertically in a range of cells, you cannot force them to flow to the next row or column.
java.awt.FlowLayout contained in the JDK automatically wraps the contained components:
JPanel mainPanel = new JPanel(new FlowLayout()); mainPanel.add(subPanel1); mainPanel.add(subPanel2); mainPanel.add(subPanel3); ...
Recommended height is disabled, but there are ways to fix this, see WrapLayout .
Regarding the second requirement:
Also, to add an extra coefficient, every time it reaches the edge, I need to add a new / different panel (timeline) - so is there a way to find when it is going to turn on a new line?
The layout manager should compose components that have already been added to the container, and not add new components based on the layout results. Adding invisible placeholder components for the timeline after each sub-panel that will be displayed by the layout manager on demand may work.
For this, you definitely need a layout manager. For starters, I would recommend taking a FlowLayout source. In the implementation of layoutContainer there is a loop that layoutContainer through all components. After wrapping the string, check if the next component is a timeline placeholder, make it visible, and wrap it again.
source share