Before I launch into a detailed explaination of my quandary, let me ask: Has anybody here ever built a UI with dynamically nested JSplitPanes? I'm using this approach to display a TreeModel of data in JLists. Or at least I'm trying to. It's working acceptably, but there seem to be a lot of hurdles on the way to that last little bit of perfection.
If you've done this, TIA for the assistance I'll be requesting. (If not, go figure it out so I can ask. J/K.)
I can't figure out what you mean by "dynamically nested" JSplitPanes. I've got an app that has some nested JSplitPanes, but not ones that get repeatedly reassembled at runtime, if that's what you mean. What kind of problems are you having?
If you've ever seen the Finder in the Mac UI, that's an example of the approach I want to use. My component accepts a TreeModel, and displays all children of the root in the leftmost JList. When the user selects an item in the list, a JList is added to the right of the first, containing the selection's children, and so on.
The implementation starts with a single JSplitPane with the first-order-children in a JList as its left component. The first selection creates a new JSplitPane with the appropriate second-order-children in a JList as its left component, and makes that new split pane the right component of the first one, and so on.
I've implemented this special purpose split pane as a subclass of JSplitPane. (SplitTreeSplitPane, STSP for short). So a STSP always has a JList in a scroll pane as its left component, and either a very thin spacer panel or another (nested) STSP as its right component. STSP implements ListSelectionListener, Scrollable, and PropertyChangeListener.
The dynamic addition and removal of nested STSP's works well; I'm making the whole thing resize appropriately and scroll to make the newly added list visible at the right times. The problems begin when the user moves any divider - I can't seem to make it resize when the dividers are dragged. Moving a divider just a little (less than the width of that rightmost spacer) works fine; the space gained in the JList to the left of the divider is lost by the spacer. Move it any more and the JLists to the right start shrinking. Move it so much that all the JLists to the right are down to minimum size, and you can't move it any more.
I'm listening to property change events for the divider location property, calculating the amount moved, and resizing up the chain. Or rather, attempting to - all attempts to set the size in the property change handler are in vain. The timing of the property change event seems to be the stumbling block. The logic that works with list selection events doesn't work there.
I really want to stick with JSplitPane and not roll my own out of JPanels, so I can get the one-touch behavior, good LAF support, etc.
Joined: Sep 19, 2000
Ok, I'll redefine the problem. I need to subclass JSplitPane to produce this behavior: When the divider is moved, only the left component should change size. The right component should keep its existing size, and the split pane itself should change size by the same amount the divider was moved.
Now, I see the difficulties with that. Philosophically, at least, the size of a component is usually controlled by the layout manager of its parent component. I'm also investigating that approach, looking for the appropriate layout manager to use in the top containing JViewport.
hi Jerry , i got the same problem some days back. i tried in several way to get out of it. (try to get listener of splitpane's divider and change the size of left and right component according to the divider position. but i am unable to do that.... ) i got the answer by changing the layout managers of left and right components of split pane.
The right component should keep its existing size place a panel in right component and its layout should be null.
Hope This Helps All The Best [ May 31, 2005: Message edited by: sasi kala ]