Example usage for java.beans PropertyChangeEvent getSource

List of usage examples for java.beans PropertyChangeEvent getSource

Introduction

In this page you can find the example usage for java.beans PropertyChangeEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:MainClass.java

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);
            }//  w  w w . j ava  2 s. com
        }
    };

    // Attach listener
    splitPane.addPropertyChangeListener(propertyChangeListener);

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

From source file:PropertySplitPane.java

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 JButton("A");
    splitPane.setTopComponent(topComponent);

    JComponent bottomComponent = new JButton("B");
    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);
            }//  ww  w  .j av  a2 s.  co  m
        }
    };

    splitPane.addPropertyChangeListener(propertyChangeListener);

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_VIEW_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//w  w  w  . java2 s.  c o  m
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//  w ww . j a  va 2 s  .  c om
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.ACCESSORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/* www . ja v a  2 s  . c  o  m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_HIDING_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/*from  w ww. ja  va2s  . c o m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }/*from  w w  w .j a v a 2s  .c  o  m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_FILTER_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//from w w w. j a  v  a2 s  . c  o m
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//from w  ww.  j  ava2 s.c o  m
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//  w  w w.ja  v a  2  s  . co  m
        }
    });
}