0

I have a simple MultiSplitPane in java. It has 1 Row (split) and 2 nodes (Leaves) in it. How can I add another row under the existing one.

Here's the code that creates the MultiSplitPane and the 2 Leaves:

List children = 
Arrays.asList(new Leaf("left"),
new Divider(), 
new Leaf("right"));
Split modelRoot = new Split();
modelRoot.setChildren(children);

MultiSplitPane multiSplitPane = new MultiSplitPane();
multiSplitPane.getMultiSplitLayout().setModel(modelRoot);
multiSplitPane.add(new JButton("Left Component"), "left");
multiSplitPane.add(new JButton("Right Component"), "right");

This is how I can add another Leaf, but I need to add new Split (row):

Leaf newLeaf = new Leaf("newLeaf");
    Split newSplit = (Split) multiSplitPane.getMultiSplitLayout().getModel();
    java.util.List newList = new ArrayList();

    newList.add(newLeaf);
    newList.add(new Divider());
    newList.addAll(newSplit.getChildren());

    newSplit.setChildren(newList);

    multiSplitPane.setModel(newSplit);
    multiSplitPane.add(new JButton("new"), "newLeaf");
    revalidate();
Igor
  • 1,532
  • 4
  • 23
  • 44
  • In most UI API's, you do this by placing the existing divider and leafs (?) in a composite widget and then placing a divider under that composite and above another leaf. Not exactly sure about this specific API set, but the concept should work. – Chris Gerken Sep 06 '12 at 20:08

1 Answers1

1

If you want to work with a second Split, you can do the following:

  • Create a couple components to put inside the second Split.
  • Make Leafs to which you will link the above components.
  • Make a new children list representing the Split's structure.
  • Create the Split and set its children to the above list.

That's the easy part. Now, here is the key:

  • Add your second Split to the first Split's children list. Note that you may have to add a divider to the first Split's children list before the second split!
  • Call "setChildren" for your first Split. From what I can tell, you must do this after having revised the Split's children list.
  • Don't forget to actually add your components to the MultiSplitPane and call "revalidate" for the MultiSplitPane.

Take a look at this sample code.

Community
  • 1
  • 1
the-konapie
  • 601
  • 3
  • 10