JCheckBox: addComponentListener(ComponentListener l) : JCheckBox « javax.swing « Java by API






JCheckBox: addComponentListener(ComponentListener l)

  

import java.awt.Component;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;

public class Main {

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

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

}

   
    
  








Related examples in the same category

1.new JCheckBox(Action a)
2.new JCheckBox(String text)
3.new JCheckBox(String text, boolean selected)
4.new JCheckBox(String text, Icon normal)
5.JCheckBox: addActionListener(ActionListener lis)
6.JCheckBox: addChangeListener(ChangeListener lis)
7.JCheckBox: addItemListener(ItemListener lis)
8.JCheckBox: isSelected()
9.JCheckBox: setBorderPaintedFlat(boolean b)
10.JCheckBox: setDisabledIcon(Icon disabledIcon)
11.JCheckBox: setDisabledSelectedIcon(Icon disabledSelectedIcon)
12.JCheckBox: setEnabled(boolean b)
13.JCheckBox: setIcon(Icon defaultIcon)
14.JCheckBox: setMnemonic(int mnemonic)
15.JCheckBox: setPressedIcon(Icon pressedIcon)
16.JCheckBox: setRolloverIcon(Icon i)
17.JCheckBox: setRolloverSelectedIcon(Icon rolloverSelectedIcon)
18.JCheckBox: setSelected(boolean b)
19.JCheckBox: setSelectedIcon(Icon i)
20.JCheckBox: setText(String text) (HTML)
21.JCheckBox: setToolTipText(String text)