Urs Reupke
Urs Reupke

Reputation: 6931

How to create a modular UI using MigLayout without nesting multiple panels?

MigLayout is a highly versatile layout manager for Swing, SWT and JavaFX. As per the documentation, it should be possible to (re-)create any given layout with just a single instance of that layout manager.

However, I could never figure out how to create a modular application with decentralized control over layouting with that single instance: I have a parent panel that controls where individual components contributed by submodules go. Aiming for decoupled and independent submodules, those components are free to choose whether they do their layout with MigLayout or with any given layout manager. Thus, they hand out an instance of Node (or JComponent), and I end up with nested layout managers.

Are there any emergent/good/best practices for achieving both decoupled architecture and adhering to MigLayout's single-instance paradigm?

Upvotes: 0

Views: 169

Answers (1)

tbeernot
tbeernot

Reputation: 2622

I understand what you want to do and have tried similar approaches. I found no generic solution; either you nest the layouts or you come to some kind of agreement between modules on usages of ranges of cells (this is what I usually end up with when for example generating search screens).

I ended up with one conclusion; having totally independent modules putting stuff on a screen works fine technically, and if you can make a high degree of separation part of the layout style, it might also work for the user. But I found that the resulting screens usually are not very user friendly, especially if there are multiple layers of construction. So I stopped trying to dynamically construct screens and just build a screen to match the task at hand; there is the end user screen, some custom controls, and maybe the occasional task specific panel (/ pane).

Upvotes: 0

Related Questions