Reset the divider position to that position by calling the resetToPreferredSizes() method of JSplitPane.
- Change the dividerLocation property with setDividerLocation(newLocation).
- 0.0 and 1.0, representing a percentage of the JSplitPane container width.
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
public class MovingJSplitPaneDivider {
public static void main(String[] a) {
JFrame horizontalFrame = new JFrame();
horizontalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent topButton = new JButton("Left");
JComponent bottomButton = new JButton("Right");
final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(topButton);
splitPane.setBottomComponent(bottomButton);
horizontalFrame.add(splitPane, BorderLayout.CENTER);
horizontalFrame.setSize(150, 150);
horizontalFrame.setVisible(true);
splitPane.setDividerLocation(0.5);
}
}
With the system-provided look and feel classes, pressing the F8 key allows you to move the divider with the keyboard keys such as Home, End, or the arrows. F8 isn't a modifier like Shift or Alt.