Get and Set the Divider Location in a JSplitPane in Java

Description

The following code shows how to get and Set the Divider Location in a JSplitPane.

Example


// www  .  j  a  va 2  s  .c o  m
import javax.swing.JButton;
import javax.swing.JSplitPane;

public class Main {
  public static void main(String[] argv) throws Exception {
    JButton leftComponent = new JButton("left");
    JButton rightComponent = new JButton("right");
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);

    int loc = pane.getDividerLocation();

    loc = (int) ((pane.getBounds().getWidth() - pane.getDividerSize()) / 2);
    pane.setDividerLocation(loc);

    double propLoc = .5D;
    pane.setDividerLocation(propLoc);
  }
}




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer