Property Split : Splitpane « Swing JFC « Java






Property Split

Property Split
  

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

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

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);

    JComponent topComponent = new OvalPanel();
    splitPane.setTopComponent(topComponent);

    JComponent bottomComponent = new OvalPanel();
    splitPane.setBottomComponent(bottomComponent);

    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);
        }
      }
    };

    splitPane.addPropertyChangeListener(propertyChangeListener);

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

class OvalPanel extends JPanel {

  Color color;

  public OvalPanel() {
    this(Color.black);
  }

  public OvalPanel(Color color) {
    this.color = color;
  }

  public void paintComponent(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    g.setColor(color);
    g.drawOval(0, 0, width, height);
  }


}

           
         
    
  








Related examples in the same category

1.Create a left-right split pane
2.Create a top-bottom split pane
3.A quick test of the JSplitPane classA quick test of the JSplitPane class
4.SplitPane Demo 2
5.Swing SplitPane SampleSwing SplitPane Sample
6.Resize SplitPaneResize SplitPane
7.SplitPane: VerticalSplitSplitPane: VerticalSplit
8.SplitPane Sample 3SplitPane Sample 3
9.Use the split paneUse the split pane
10.Continuously move the divider and resize its child components while the user is dragging the divider
11.Getting the Setting the Children in a JSplitPane Container
12.Getting and Setting the Divider Location in a JSplitPane Container
13.Distributing Space When a JSplitPane Container Is Resized
14.The split pane supports a one-touch-expandable capability that allows the user to conveniently move the divider to either end with a single click
15.This program demonstrates the split pane component organizer.This program demonstrates the split pane component organizer.