JSplitPane: getDividerLocation() : JSplitPane « javax.swing « Java by API






JSplitPane: getDividerLocation()

  
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;

public class MainClass {
  public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Property Split");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    splitPane.setTopComponent(new JLabel("www.java2s.com"));

    splitPane.setBottomComponent(new JLabel("www.java2s.com"));

    PropertyChangeListener propertyChangeListener =
        new PropertyChangeListener() {
      public void propertyChange (PropertyChangeEvent changeEvent) {
        JSplitPane sourceSplitPane = (JSplitPane)changeEvent.getSource();
        String propertyName = changeEvent.getPropertyName();
        if (propertyName.equals(
            JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
          int current = sourceSplitPane.getDividerLocation();
          System.out.println ("Current: " + current);
          Integer last = (Integer)changeEvent.getNewValue();
          System.out.println ("Last: " + last);
          Integer priorLast = (Integer)changeEvent.getOldValue();
          System.out.println ("Prior last: " + priorLast);
        }
      }
    };

    // Attach listener
    splitPane.addPropertyChangeListener(propertyChangeListener);

    frame.add(splitPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
  }

}


           
         
    
  








Related examples in the same category

1.JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY
2.JSplitPane.VERTICAL_SPLIT
3.new JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
4.JSplitPane: addHierarchyListener(HierarchyListener l)
5.JSplitPane: getBottomComponent()
6.JSplitPane: getLeftComponent()
7.JSplitPane: getRightComponent()
8.JSplitPane: getTopComponent()
9.JSplitPane: resetToPreferredSizes()
10.JSplitPane: setContinuousLayout(boolean newContinuousLayout)
11.JSplitPane: setDividerLocation(double proportionalLocation)
12.JSplitPane: setDividerSize(int newSize)
13.JSplitPane: setLeftComponent(Component comp)
14.JSplitPane: setOneTouchExpandable(boolean newValue)
15.JSplitPane: setOrientation(JSplitPane.HORIZONTAL_SPLIT)
16.JSplitPane: setResizeWeight(double value)
17.JSplitPane: setRightComponent(Component comp)