You are on page 1of 9

JAVA Swing :- a set of gui classes

-Is a part of Java Foundation Classes (JFC) that is used to create window-
based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API
and entirely written in java.

-JFC :-The Java Foundation Classes (JFC) are a set of GUI components which
simplify the development of desktop applications.

-The javax.swing package provides classes for java swing API such as JButton,
JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.

-Part of java's Standard library

- Swing follows MVC.Contents and Shapes are Seperated(MVC Support),Platform Independent

Features of Java Swing:-

1. Look and Feel

2.Data Transfer

3.Internalization and Localization

4.Accessibility

5.System Tray Icon Support


JAVA Swing Components:-
*Containers:- Contain and manage other components.

1-Top-Level/Internal Containers,Ex:-JFrame

2-General Purpose Containers

3-Special Purpose Containers

4-Basic Controls

5-Uneditable Information Displays

6-Interactive Displays of Highly Formatted Information

1. TOP LEVEL CONTAINERS :-


* JFrame :-

The javax.swing.JFrame class is a type of container which inherits the


java.awt.Frame class. JFrame works like the main window where
components like labels, buttons, textfields are added to create a GUI.

Unlike Frame, JFrame has the option to hide or close the window with the
help of setDefaultCloseOperation(int) method.

import javax.swing.JFrame;  
public class JFrameExample {  
 JFrame frame = new JFrame("JFrame Example");  }

*Basic Controls:-Atomic Components

-Used for Showing Output.

-Inherits JComponents

-Ex:- JButton, JTextArea, JTable.

* JDialog :-
The JDialog control represents a top level window with a border and a title
used to take some form of input from the user. It inherits the Dialog class.

Unlike JFrame, it doesn't have maximize and minimize buttons.

JDialog class declaration


public class JDialog extends Dialog implements WindowConstants, Accessible, R
ootPaneContainer  

2. GENERAL PURPOSE CONTAINERS :-


*JPanel :-

The JPanel is a simplest container class. It provides space in which an


application can attach any other component. It inherits the JComponents class.

It doesn't have title bar.

JPanel class declaration

public class JPanel extends JComponent implements Accessible  

*JToolBar :-

JToolBar container allows us to group other components, usually buttons


with icons in a row or column. JToolBar provides a component which is
useful for displaying commonly used actions or controls.

Nested Classes
Modifier and Class Description
Type

protected class JToolBar.AccessibleJToolBar This class implements accessibility


support for the JToolBar class.

static class JToolBar.Separator A toolbar-specific separator.


*JScrollPane :-

A JscrollPane is used to make scrollable view of a component.


When screen size is limited, we use a scroll pane to display a large
component or a component whose size can change dynamically

public class JScrollPaneExample;

 
3. SPECIAL PURPOSE CONTAINERS :-

*JLayeredPane :-

The JLayeredPane class is used to add depth to swing container. It is used to


provide a third dimension for positioning component and divide the depth-range
into several different layers.

JLayeredPane class declaration:-

public class JLayeredPane extends JComponent implements 

Accessible; 

*JRootPane :-

JRootPane is a lightweight container used behind the scenes by JFrame,


JDialog, JWindow, JApplet, and JInternalFrame.

import javax.swing.JRootPane;  
public class JRootPaneExample;

4. BASIC CONTROLS :-

*JButton :-

The JButton class is used to create a labeled button that has platform
independent implementation. The application result in some action when the
button is pushed. It inherits AbstractButton class.
JButton class declaration
declaration for javax.swing.JButton class.

public class JButton extends AbstractButton implements Accessible

*JComboBox :-
The object of Choice class is used to show popup menu of choices.
Choice selected by user is shown on the top of a menu. It
inherits JComponent class.
JComboBox class declaration
Let's see the declaration for javax.swing.JComboBox class.

public class JComboBox extends JComponent implements ItemSelectable, ListD
ataListener, ActionListener, Accessible;
 *JList :-
The object of JList class represents a list of text items. The list of text items
can be set up so that the user can choose either one item or multiple items. It
inherits JComponent class.
JList class declaration
Let's see the declaration for javax.swing.JList class.
public class JList extends JComponent implements Scrollable, 

Accessible; 

*JMenu :-

The JMenuBar class is used to display menubar on the window or frame. It


may have several menus.

The object of JMenu class is a pull down menu component which is displayed from
the menu bar. It inherits the JMenuItem class.

The object of JMenuItem class adds a simple labeled menu item. The items used in
a menu must belong to the JMenuItem or any of its subclass.

JMenuBar class declaration :-


public class JMenuBar extends JComponent implements MenuElement, A
ccessible  

JMenu class declaration :-


public class JMenu extends JMenuItem implements MenuElement, Access
ible  

JMenuItem class declaration :-


public class JMenuItem extends AbstractButton implements Accessible, 
MenuElement 

5. UNEDITABLE INFORMATION DISPLAYS :-

*JLabel :-
JLabel class is used to render a read-only text label or images on the
UI. It does not generate any event.
JLabel class declaration :-
JLabel textLbl = new JLabel(“This is a text label.”);

JLabel imgLabel = new JLabel(homeIcon);


*JProgressBar :-

The JProgressBar class is used to display the progress of the task. It


inherits JComponent class.

JProgressBar class declaration :-


Let's see the declaration for javax.swing.JProgressBar class.

public class JProgressBar extends JComponent implements SwingConstants, Acc
essible;  

6. INTERACTIVE DISPLAYS OF HIGHLY FORMATED INFORMATION :-

  *JTextArea :-

The object of a JTextArea class is a multi line region that displays text.
It allows the editing of multiple line text. It inherits JTextComponent class

JTextArea class declaration :-

Let's see the declaration for javax.swing.JTextArea class.

public class JTextArea extends JTextComponent
*JTable :-
The JTable class is used to display data in tabular form. It is
composed of rows and columns.

JTable class declaration :-


Let's see the declaration for javax.swing.JTable class.

JTable(Object[][] rows, Object[] columns)

*JColorChooser :-
The JColorChooser class is used to create a color chooser dialog box
so that user can select any color. It inherits JComponent class.
JColorChooser class declaration :-
Let's see the declaration for javax.swing.JColorChooser class.

public class JColorChooser extends JComponent implements Accessible 

*JFilleChooser :-

The object of JFileChooser class represents a dialog window from


which the user can select file. It inherits JComponent class.

JFileChooser class declaration :-


Let's see the declaration for javax.swing.JFileChooser class.

public class JFileChooser extends JComponent implements 

Accessible;  
*JTree:-

The JTree class is used to display the tree structured data or hierarchical
data. JTree is a complex component. It has a 'root node' at the top most
which is a parent for all nodes in the tree. It inherits JComponent class.
JTree class declaration :-
Let's see the declaration for javax.swing.JTree class.
public class JTree extends JComponent implements Scrollable, Accessible

  

You might also like