4

我正在尝试使用 SwingX 的 MultiSplitPane 和 MultiSplitLayout。我知道如何将 MultiSplitLayout 与方法 parseModel 一起使用(请参阅http://today.java.net/pub/a/today/2006/03/23/multi-split-pane.html)。但是我不明白没有这种方法的机制。如何重现这个?

String layoutDef =
    "(COLUMN (ROW weight=1.0 left (COLUMN middle.top middle middle.bottom) right) bottom)";
MultiSplitLayout.Node modelRoot = MultiSplitLayout.parseModel(layoutDef);
4

1 回答 1

7

好的,我终于自己找到了答案。您应该先看图片以了解代码。

Split column1 = new Split();
column1.setRowLayout(false);

Split row = new Split();

Split column2 = new Split();
column2.setRowLayout(false);

column2.setChildren(new Leaf("middle.top"), new Divider(), new Leaf(
    "middle"), new Divider(), new Leaf("middle.bottom"));

row.setChildren(new Leaf("left"), new Divider(), column2,
    new Divider(), new Leaf("right"));

column1.setChildren(row, new Divider(), new Leaf("bottom"));

// Once the layout is done, the code is easy
JXMultiSplitPane msp = new JXMultiSplitPane();
MultiSplitLayout layout = new MultiSplitLayout(column1);
msp.setLayout(layout);
msp.add(new JButton("bottom"), "bottom");
msp.add(new JButton("left"), "left");
msp.add(new JButton("right"), "right");
msp.add(new JButton("middle.bottom"), "middle.bottom");
msp.add(new JButton("middle"), "middle");
msp.add(new JButton("middle.top"), "middle.top");

图片理解代码背后的逻辑。 (来源:java.net模型 og 布局

于 2011-12-29T16:02:37.073 回答