Component and containers
Component
A component is an independent visual control, such as a push button or slider.
A component is an object with a graphical representation that can be displayed on the screen and interact with the user. Examples of components include buttons, checkboxes, and scrollbars commonly found in graphical user interfaces.
- Swing components inherit from the javax.Swing.JComponent class, which is the root of the swing component hierarchy.
- Swing components are derived from the JComponent class.
- JComponent provides the functionality that is common to all components. For example, JComponent supports the pluggable look and feel.
- JComponent inherits the AWT classes Container and component. Thus, a swing component is built on and compatible with an AWT component.
- All of the swing's components are represented by classes defined within the package javax.swing.
The following table shows the class names for swing components
- JApplet
- JColorChooser
- JDialog
- JFrame
- JLayeredPane
- JMenuItem
- JPopupMenu
- JRootPane
- JSlider
- JTable
- JToggleButton
- JViewport
- JButton
- JComboBox
- JEditorPane
- JInternalFrame
- JList
- JOptionPane
- JProgressBar
Notice that all component classes begin with the letter J
Containers
A container holds a group of components. Thus a container is a special type of component that is designed to hold other components.
Containers are the interface between a component and the low-level, platform-specific functionality that supports the component. Before it can be executed, a web, enterprise bean, or application client component must be assembled into a Java EE module and deployed into its container.
Commonly used containers are:
Panel, Frame, window.
Panel
JPanel is the simplest container. It provides space in which any other component can be placed, including other panels.
Frame
A JFrame is a top-level window with a title and a border.
Window
A JWindow object is a top-level window with no borders and no menubar.
Types of Containers
Swing defines two types of Containers.
The first are top-level containers: JFrame, JApplet, JWindow and JDialog.
These containers do not inherit JComponent.They inherit the AWT classes Component and Container. These containers are heavyweight.
The second type of container is lightweight. This makes the top-level containers a special case Swing component library.
Comments
Post a Comment