Friday, September 7, 2012

Basic JSplitPane

JSplitPane is used to divide two (and only two) Components. The two Components are graphically divided based on the look and feel implementation, and the two Components can then be interactively resized by the user.

Basic 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;
        JPanel jPanel1, jPanel2;
        
        public MyJFrameWin(){
            this.setTitle("java-buddy.blogspot.com");
            this.setSize(400, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            jPanel1 = new JPanel();
            jPanel2 = new JPanel();
            
            jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
                    jPanel1, jPanel2);
            jSplitPane.setOneTouchExpandable(true);
            jSplitPane.setDividerLocation(150);
            
            getContentPane().add(jSplitPane);
        }
    }
}


Next:
- Nested JSplitPane


No comments:

Post a Comment