Monday, September 10, 2012

Nested JSplitPane

Example of Nested JSplitPane:

Nested JSplitPane


package javatestsplitpane;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaSplitPane {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(runJSplitPaneLater);
    }
    
    static Runnable runJSplitPaneLater = new Runnable(){

        @Override
        public void run() {
            MyJFrameWin myJFrameWin = new MyJFrameWin();
            myJFrameWin.setVisible(true);
        }
        
    };
    
    public static class MyJFrameWin extends JFrame{
        
        JSplitPane jSplitPane, jSplitPane2;
        JPanel jPanel1, jPanel2a, jPanel2b;
        
        public MyJFrameWin(){
            this.setTitle("java-buddy.blogspot.com");
            this.setSize(400, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            jPanel1 = new JPanel();
            jPanel2a = new JPanel();
            jPanel2b = new JPanel();
            
            jSplitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, 
                    jPanel2a, jPanel2b);
            jSplitPane2.setOneTouchExpandable(true);
            jSplitPane2.setDividerLocation(100);
            
            jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
                    jPanel1, jSplitPane2);
            jSplitPane.setOneTouchExpandable(true);
            jSplitPane.setDividerLocation(150);
            
            getContentPane().add(jSplitPane);
        }
    }
}


No comments:

Post a Comment