Split panel in java is mainly used to create dynamic dividers or sections on your frame. You can either add vertical or horizontal split. In one split panel you can add only two components. You can add one split panel in another one.
Here I am giving one very simple example of split panel.
Code:
import java.awt.Button;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
class Test
{
JFrame frm = new JFrame();
public Test()
{
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new Button("B2"), new Button("B2"));
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(150);
frm.add(splitPane);
frm.setSize(500,500);
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new Test();
}
}
Here you can see that I have added two buttons in split panel. Run this program and you will see that you can resize any section as much as you want. Even you can hide one section.
No comments:
Post a Comment