The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JSplitPane  [5 examples]

e825. Distributing Space When a JSplitPane Container Is Resized

The weight of a split pane controls the behavior of the divider when the split pane is resized. If the weight is 0, all extra space is given to the right or bottom component. If the weight is 1, all extra space is given to the left or top component. A weight of .3 specifies that the left or top component gets one-third of the extra space. The weight also determines how the children lose space when the size of the split pane is reduced. For example, a weight of 0 means that the left or top component does not lose any space.

The weight also controls the starting location of the divider. For example, if the weight is .5, the divider is placed in the center.

    // Create a left-right split pane
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
    
    // Get current weight
    double weight = pane.getResizeWeight();    // 0.0 by default
    
    // Keep the size of the right component constant
    weight = 1D;
    pane.setResizeWeight(weight);
    
    // Split the space evenly
    weight = .5D;
    pane.setResizeWeight(weight);

 Related Examples
e823. Creating a JSplitPane Container
e824. Getting the Setting the Children in a JSplitPane Container
e826. Getting and Setting the Divider Location in a JSplitPane Container
e827. Setting the Size of the Divider in a JSplitPane Container

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.