1. Jcomponent Class
Understanding Component ClassThe Component class
serves as a base class for a wide range of and it supports the
addition of child components. These child compon to a
Component using various methods, allowing you to create
compl user interfaces. Here are some common methods and
concepts relat managing child components within a
JComponent :
1. 1. add(Component comp): This method allows you to
add a child a Component. You can pass any Component
object, such as instan JLabel, JTextField, or other Swing
components, as an argument to thisExample :
2. JPanel panel = new JPanel;
JButton button = new Button("Click Me");
panel.add(button);//Add the button as child component
2. Layout Managers: When you add child components
to JComponent,the layout manager associated with that
JComponent determines are arranged and sized. Swing
provides various layout manaers.like flowlayout,,Border
Layout ,GridLayoutl
JPanel = new JPanel(); / / Default layout manager is
FlowLayout
JButton button1 = new ]Button("Button 1");
3. Jbutton Button2=new Jbutton(“Button 2”);
Panel.add(button1);
Panel.add(button2);
3.Removing Child Components: you can remove
child components from a Jcomponent using
remove(Component comp) method
Examples:
Panel.remove(button1);//Remove button1 from
panel
4. 4.Component Hierarchy : Swing Components can be
oranized into a hierarchical structure wherea
Jcomponent can coantain other Jcomponent object
Example:
Jpanel parentPanel=new Jpanel();
Jpanel childPanel=new Jpanel();
parentPanel.add(childPanel);//Adding child panel as
child to parentpanel
5.getComponent(int index):you can recive a child
component from Jcomponent by its index using this
method
6. Example:
parentPanel.add (button1);// buttont is added first and appears behind other
component
parentPanel.add (button2);// button? is added later and appears in front of buttonl
Classes related Jcomponent Class:
In the java Swing library,numerous GUI component are derived the Jcomponent
class Here's a list of some commonly used GUl components the
• Ibutton: A clickable button that triggers an action when pressed.
• Jlabel: A non-editable text or image component used for displaying
information.
• JextField: A single-line text input field for user data entry.
• ItextArea: A multi-line text area used for entering or displaying larger blocks
• IcheckBox: A checkbox that can be checked or unchecked by the user. Often for
binary choices.
• JradioButton : A radio button used for selecting one option from a grog options
where only one can be selected.
• JcomboBox: A dropdown list that allows users to select an item from a list
choices.
7. Jlist : A component used for displaying a list of item often with single or
multiple item selection.
• Jtable: A versatile component for displaying and editing tabular data , such as
spreadsheets or
JscrollPane : A components that provides scrolling capabilites to other
component when their contain exceeds the visible area
• JsplitPane: A container that allows two componernts to be divider, often used
for resizable panes.
• Jprogress Bar: A visual component that displays by a movable divider, often
used for resizable panes
• Jslider: A component that lets the user select a value by dragging a along a
track.
JmenuBar : A component for creating menu bars at the top of the appilcation
window. It contains menus and menu items.
JtoolBar: A container for creating toolbars containing buttons for for freqently
used actions.
JfileChooser: A component for displaying a file dialog that allows users to
select s files or directories.
8. • Jpanel: A generic container for grouping and
organizing other components within a window
• Jdialog : A dialog box that is typically used for
interaction with the user or gathering input
• Jframe: A top –level container representing the
main application window
9. • Jpanel: A generic container for grouping and
organizing other components within a window
• Jdialog : A dialog box that is typically used for
interaction with the user or gathering input
• Jframe: A top –level container representing the
main application window