2011-12-28 5 views
4

私はMultiSplitPaneとMultiSplitLayoutをSwingXから使用しようとしています。私はMultiSplitLayoutをparseModelメソッドで使用する方法を知っています(http://today.java.net/pub/a/today/2006/03/23/multi-split-pane.html参照)。しかし、私はこの方法のないメカニズムを理解していません。 これを再現するには?SwingXでMultiSplitLayoutを使用するには?

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

答えて

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"); 

コードの背後にある論理を理解するための画像です。 model og the layout http://today.java.net/images/2006/03/example3-diagram.gif

関連する問題