I’m working on a text editor in which the user is free to divide the editor window vertically or horizontally any number of times (ie, into any number of panes). A single window can be divided both vertically and horizontally (for example, 2 rows, one which contains 3 columns, etc). Each pane contains a JTextArea inside a JScrollPane and a status bar.
My approach thus far has been to use nested JSplitPanes. I’ve struggled to arrange the split pane dividers so that the space in the window is divided equally among all the vertically- or horizontally-split panes. I’ve come quite close to getting it right, but I’ve had to resort to using setPreferredSize() in a number of places (Should I avoid the use of set[Preferred|Maximum|Minimum]Size methods in Java Swing?).
I am wondering if it would be easier/better to take a different approach entirely. MultiSplitPane looks tempting…
What would be the best layout/approach for my situation?
I decided to invest some time in learning the MultiSplitPane layout. It looks like a good solution.
Here is the code I wrote as a test. It’s essentially a simulation of a layout that changes dynamically as the user splits the window in various ways. It’s a bit lengthy, but maybe it will be helpful to someone who is trying to learn MultiSplitPane.
The end result looks like this: