Saturday, 15 April 2017

Swing Components and Containers

  • Swing contains two key items i.e components and containers.
  • Components are independent visual controls.
  • Conatiners builts a group of components.
  • Swing Containers  are of two types light-weight and heavy-weight.
    • All components of swing are derived from JComponent class.
    • JComponent do inherit component class and container class of awt.
    • JFrame, JApplet, JDialog and JWindow these are all swing containers but they do not inherit JComponent instead they directly inherit component and container class of awt.
    • Since awt is heavy-weight because it is platform independent, JFrame, JApplet, JDialog and JWindow do inherits awt component and container class and hece they are also heavy-weight.
    • Top-level containers are not containd within any other container.
    • All the swing component which inherits JComponent class are light-weight.
    • An example of light-weight container is JPanel which is a general purpose container.
    • Swing components are available in javax.swing package and some of the swing  events which are not defined in AWTEvent class are present in javax.swing.event  package

✭Swing components Constructor

  • JButton
  1. JButton();
  2. JButton(String str);
  3. JButton(ImageIcon image);
  4. JButton(String str, ImageIcon image);
  • JLabel
  1. JLabel();
  2. JLabel(String str);
  3. JLabel(Icon image);
  4. JLabel(String str, Icon image, int horizotalAlignment);
  5. JLabel(String str, int horizotalAlignment);
  • JRadioButton
  1. JRadioButton()
  2. JRadioButton(Action a)
  3. JRadioButton(Icon icon, boolean selected)
  4. JRadioButton(String text, boolean selected)RadioButton(String text, Icon icon)
  5. JRadioButton(String text, Icon icon, boolean selected)
  • JComboBox
  1. JComboBox()
  2. JComboBox(ComboBoxModel aModel)
  3. JComboBox(Object[] items)
  4. JComboBox(Vector<?> items)

0 comments:

Post a Comment