This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Test Multisplit

By: a guest on Apr 5th, 2012  |  syntax: Java  |  size: 2.32 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.HeadlessException;
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.border.EmptyBorder;
  8. import org.jdesktop.swingx.JXMultiSplitPane;
  9. import org.jdesktop.swingx.MultiSplitLayout;
  10.  
  11. /**
  12.  * Test Multisplit.
  13.  *
  14.  * @author Martin Miller
  15.  * @version 0.1 2012-04-05
  16.  * @see http://www.java.net/comment/reply/884868
  17.  */
  18. public class TestMultiplitSplit extends JFrame {
  19.  
  20.     private JXMultiSplitPane msp;
  21.     private MultiSplitLayout.Split splitModel;
  22.  
  23.     public TestMultiplitSplit() throws HeadlessException {
  24.         super("test");
  25.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.  
  27.         // MultiSplit Layout
  28.         msp = new JXMultiSplitPane();
  29.         splitModel = new LeftRightSplitPaneModel();
  30.         msp.getMultiSplitLayout().setModel(splitModel);
  31.         MultiSplitLayout layout = msp.getMultiSplitLayout();
  32.         msp.setBorder(new EmptyBorder(2, 2, 2, 2));
  33.  
  34.         setLayout(new BorderLayout());
  35.        
  36.         msp.add(new JButton("LEFT"), LeftRightSplitPaneModel.LEFT);
  37.         msp.add(new JButton("RIGHT"), LeftRightSplitPaneModel.RIGHT);
  38.        
  39.         layout.layoutByWeight(msp); // <-- Might be important for good results
  40.         add(msp, BorderLayout.CENTER);
  41.  
  42.         setSize(new Dimension(800,600));
  43.         setLocationRelativeTo(null);
  44.     }
  45.  
  46.     /**
  47.      * MultiSplitPane Layout.
  48.      *
  49.      * +--------+---------+
  50.      * |        |         |
  51.      * |   l    |    r    |
  52.      * |        |         |
  53.      * +--------+---------+
  54.      */
  55.     class LeftRightSplitPaneModel extends MultiSplitLayout.Split {
  56.  
  57.         public static final String LEFT = "l";
  58.         public static final String RIGHT = "r";
  59.         protected MultiSplitLayout.Leaf left = new MultiSplitLayout.Leaf(LEFT);
  60.         protected MultiSplitLayout.Leaf right = new MultiSplitLayout.Leaf(RIGHT);
  61.  
  62.         public LeftRightSplitPaneModel() {
  63.             super();
  64.  
  65.             setRowLayout(true);
  66.             left.setWeight(0.3);
  67.             right.setWeight(0.7);
  68.             this.setWeight(1.0);
  69.  
  70.             setChildren(left, new MultiSplitLayout.Divider(), right);
  71.         }
  72.     }
  73.  
  74.     public static void main(String[] args) {
  75.         JFrame f = new TestMultiplitSplit();
  76.         f.setVisible(true);
  77.     }
  78. }
clone this paste RAW Paste Data