Example usage for javax.swing JButton addComponentListener

List of usage examples for javax.swing JButton addComponentListener

Introduction

In this page you can find the example usage for javax.swing JButton addComponentListener.

Prototype

public synchronized void addComponentListener(ComponentListener l) 

Source Link

Document

Adds the specified component listener to receive component events from this component.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    ComponentListener comp = new ComponentListener() {
        public void componentHidden(ComponentEvent e) {
            dump("Hidden", e);
        }/*from   w w  w .ja  v  a2  s  .  c o  m*/

        public void componentMoved(ComponentEvent e) {
            dump("Moved", e);
        }

        public void componentResized(ComponentEvent e) {
            dump("Resized", e);
        }

        public void componentShown(ComponentEvent e) {
            dump("Shown", e);
        }

        private void dump(String type, ComponentEvent e) {
            System.out.println(e.getComponent().getName() + " : " + type);
        }
    };

    JButton left = new JButton("Left");
    left.setName("Left");
    left.addComponentListener(comp);

    final JButton right = new JButton("Right");
    right.setName("Right");
    right.addComponentListener(comp);

    ActionListener action = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            right.setVisible(!right.isVisible());
        }
    };
    left.addActionListener(action);

    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, left, right);

    contentPane.add(pane, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.show();
}