Example usage for javax.swing JCheckBox addComponentListener

List of usage examples for javax.swing JCheckBox addComponentListener

Introduction

In this page you can find the example usage for javax.swing JCheckBox 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:UsingComponentListener.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JCheckBox checkbox = new JCheckBox("Label visible", true);
    checkbox.addComponentListener(new ComponentListener() {
        public void componentHidden(ComponentEvent e) {
            System.out.println("componentHidden event from " + e.getComponent().getClass().getName());
        }/*from   w w w.  j a v a2  s.  c  o m*/

        public void componentMoved(ComponentEvent e) {
            Component c = e.getComponent();
            System.out.println("componentMoved event from " + c.getClass().getName() + "; new location: "
                    + c.getLocation().x + ", " + c.getLocation().y);
        }

        public void componentResized(ComponentEvent e) {
            Component c = e.getComponent();
            System.out.println("componentResized event from " + c.getClass().getName() + "; new size: "
                    + c.getSize().width + ", " + c.getSize().height);
        }

        public void componentShown(ComponentEvent e) {
            System.out.println("componentShown event from " + e.getComponent().getClass().getName());
        }

    });

    frame.add(checkbox, "North");

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ComponentEventDemo.java

public ComponentEventDemo() {
    super(new BorderLayout());

    display = new JTextArea();
    display.setEditable(false);//from w  w w. ja v a2  s. co  m
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(350, 200));

    JPanel panel = new JPanel(new BorderLayout());
    label = new JLabel("This is a label", JLabel.CENTER);
    label.addComponentListener(this);
    panel.add(label, BorderLayout.CENTER);

    JCheckBox checkbox = new JCheckBox("Label visible", true);
    checkbox.addItemListener(this);
    checkbox.addComponentListener(this);
    panel.add(checkbox, BorderLayout.PAGE_END);
    panel.addComponentListener(this);

    add(scrollPane, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
    frame.addComponentListener(this);
}