You are on page 1of 18


Swing is part of Java Foundation Class (JFC) library, is an extension of the AWT that has been integrated in java2.Swing Component depends on the fundamental classes defined within the java.awt package.

Java Foundation Class
AWT was modeled after HTML controls and allocates one operating System window per component. Because there are a lot more controls out there that programmers have become used to using, third parties began producing their own controls sets for use with java. When Netscape introduce its Internet Foundation Classes (IFC) library used for java and those classes become popular,Sun decided to act , and joint effort between Sun and Netscape produces original Swing as a part of JFC.( On April 2,1997)
What’s in JFC:

• • • • • •

SWING- The large UI package Cut and paste-Clipboard support Accessibility features-Aimed at user with disability The desktop colors features-First introduce in jdk1.1 Java 2D-Improved color image nd text support Printing-Originally enable in java1.1

Swing introduced three significant advances: • It uses fewer system resources. • Add a lot more sophisticated component. • Let you tailor the look and feel of your program.

. JComponent is derived from AWT Container class. which has no heavyweight class. Quick Note: 1. Such component are called heavyweight. a large number of such window slow performance and uses up a great deal of display anything in a windowed environment. LIGHTWEIGTH COMPONENT Each AWT component gets its own operating platform window (and therefore ends up looking like a standard control in the operating platform).In extended programs. we need heavyweight components (windows). Not all component of swing are lightweight. so they use far fewer system resources.The Swing Class Hierarchy Object Component Container Window Frame JApplet JRootPane JComponent JLayerPane JPanel JFrame JFrame HEAVYWEIGHT vs. We can mix AWT controls with swing controls(in this case AWT control appear on top of them since in swing controls are drawn on container). Therefore they are called lightweight. Swing is simply drawn as image in their container and don’t have an operating platform window at own at all. 3. 2.

we can use the setDebuggingGraphicsOption() method to set up graphics debugging. Heavyweight classes of swing: of those small window that appear when mouse hovers over a component. among other things. Easy scolling-we can connect scrolling to various component. The CellEditorimplements the wrapper BoundedRangeModel ButtonModel CellEditor .JApplet and JWindow. Tooltips.*. Pluggable look and feel-we can set the appearance of applet and application to one of three standard looks-Windows. New layout manager-BoxLayout and OverlayLayout manager. that you can watch each line as it’s drawn and make it flash.4. • • • • • Classes and Interfaces Package: javax. It defines the state model for the buttons like: radio buttons.swing. check boxes etc. This interface used by the developer for creating the new editor and it has the new components implement interfaces. Interfaces Action Descriptions This interface performed the action with the ActionListener where the multiple controls are used for same purposes.JDialog. Graphics debugging. Swing Features • • Border-we can draw border in many different style around component using setBorder method. Motif (UNIX) or Metal(standard swing look). Easy Mouseless operation-easy to connect keystrokes to component. This interface defines the data model of components like: sliders and progressBars.we use setToolTipText() method of JComponent to give component tooltip. Here the following APIs interfaces and classes are available: The following interfaces and it's descriptions to be used by the Java swing.

It gets the value of each cell of list. Renderer It defines the requirements of an object for displaying the values. The JInternalFrameimplements in the JDesktopPane with the help of DesktopManager. RootPaneContainer This interface uses the RootPane properties and it has the components like: JFrame.based approach. Scrollable This interface provides the scrolling to . It is a mutable version of ComboBoxModel. the editor component used to JComboBoxcomponents. which are stable or not. ListModel This interface used for JList components method. ListSelectionModel This interface indicates the components. ComboBoxModel This interface represents the data model in a list model with the selected items. DesktopManager This interface has JDesktopPane object. ComboBoxEditor In this interface. MutableComboBoxModel This interface extends from the ComboBoxModel. MenuElement This interface used where the any components are implements in the menu. JInternalFrame and JWindow etc. It has fixed size picture.KeySelectionManager This interface has KeySelectionManager and used for the combo box data model. ListCellRenderer This interface used for paint the cell in the list with the help of "rubber stamps" . JComboBox. Icon This interface used to graphical representation of the components.

You can set the components on the screen to own requirements.createValue() method. . This class defines the data model which provides the list with its contents. Classes AbstractAction AbstractButton AbstractCellEditor AbstractListModel ActionMap Descriptions This class handles the any types of action and provides JFC Action interface. This enables one to store an entry in the default table.ScrollPaneConstants SingleSelectionModel SwingConstants UIDefaults. This class works with InputMap and performs any action when the key is pressed. This class defines the nature of buttons and menu items. This interface has two methods setDefaultCloseOperation and getDefaultCloseOperation and provides the window close opration. It constructs the DefaultListCellRenderer. The following classes and it's descriptions to be used by the Java swing. This interface used to select the one index in a model. It provides a list and contents of the data model.ActiveValue UIDefaults. This interface used for JScrollPane components.LazyValue WindowConstants show the large amount of data with the help of JScrollPane. The entered value is not constructed until first time is a real value is created through it usingLazyValue.

Filler BoxLayout ButtonGroup CellRandererPane ComponentInputMap DebugGraphics DefaultBoundedRangeModel DefaultButtonModel DefaultCellEditor DefaultComboBoxModel DefaultDesktopManager DefaultFocusManager DefaultListCellRanderer This class extends from Object and creates the Border instance in the factory. This class used to insert the components like: JList. JTable and JTree. It provides the default model for combo boxes. It implements the TableCellEditor and TreeCellEditor for the table and tree cells. It implements the default ListCellRanderer. The Box container uses this class. This class uses the arranging the multiple components either horizontally or vertically. This class has ComponentInputMap constructor and creates the components with the help of InpuMap.BorderFactory Box Box. It provides the fixed spaces between two components and uses theBoxLayout object of the layout manager. This class implements the generic ButtonModel. The DesktopManager has the JInternalFrame for creating the internal fame in a frame. It implements the DesktopManager. It extends from the Graphics and used to debug the graphics This class provides the implementation of default BoundedRangeModel. It provides the implementing the FocusManager. . This class participates in the Layout and uses the lightweight components. This class used to create the multiple buttons in a ButtonGroupobject.

JCheckBox This class extends the JToggleButton and implements the check box in which buttons are selected or deselected. JButton This class extends the AbstractButton and you can create the new button. you .Vector.UIResource This extends the DefaultListCellRanderer and implementing in theUIResource. InputVerifier This class helps you when you works with the text fields through the focus.DefaultListCellRanderer. FocusManager It handles all focus like: gainedFocus and lostFocus. JApplet This class extends the Applet and implements the Accessible andRootPaneContainer. Here. ImageIcon This class implements the Icon and paints the icons from the images. DefaultSingleSelectionModel This class provides the default SingleSelectionModel. It bounds data between the input event and an object. GrayFilter It extends the RGBImageFilter and used for disabling the image through the button. InputMap This class uses the ActionMap to performed the action when you press any key of keyboard. JCheckBoxMenuItem It extends the JMenuItem and determines the items which is selected or deselected. DefaultListModel It extends the AbstractListModel and implementing thejava. JColorChooser It extends the JComponent and implementing the Accessable. DefaultListSelectionModel This class used for select the list in a data model.util.

JComboBox JComponent JDesktopPane JDialog JEditorPane JFileChooser JFrame JInternalFrame JInternalFrame. . The JInternalFrame added into the JDesktopPane. It edits the component by the EditorKit. All components are used the JComponent except the top-level containers like: JFrame. The JDesktopPane has DesktopManager. This class provides the facility to choosing the file. resizing and menu bar of the internal frame. This class used to create the dialog window and when you want to create the custom dialog window with the help of JOptionPane method. It displays the desktop icon and create the instance of JInternalFrame and iconify. This class extends the JLayeredPane and when you create the object of JInternalFrame to be maintained in the JDesktopPane. It extends the Dialog.JDesktopIcon JLabel JLayeredPane choose and manipulate the colors. This class extends the JTextComponent. It extends the Frame and supports the swing components architecture. It provides the drop-down list where user select only one item or value at a time. This class extends the JComboBox. But combo box is a combination of multiple text or buttons etc. It has JFC/Swing container that can be used to overlap the components to each other. This class used to show the small text and image. In java swing. closing. This class extends from the JComponent and provides the facility to dragging. JDialog etc.

Here. It extends the JComponent and used to create a new panel. When you select the item then shows the popup menu items in the JMenuBar. It used to create a new menu bar where the JMenu objects are added. It provides the single line text editing.Separator JProgressBar JRadioButton JRadioButtonMenuItem JRootPane JScrollBar This class used to create a list where you select the one or more than objects. This class used to create a scroll bar. It provides the view content area where you . for providing the task-orientation and functionality. It extends the JMenuItem and implements the radio button menu item This class provides the component behind the scenes by JFrame. It shows the integer types values in percent within a bounded range to determine the working process. Here the popup menu and the separator are available. This class used to create new menu items in the mebus.JList JMenu JMenuBar JMenuItem JOptionPane JPanel JPassworkField JPopupMenu JPopupMenu. error dialog box etc. JDialog etc. don't available the original characters but view type indication characters are available. It used to create some different types of dialog box like: message dialog box. This class used to create a popup menu. JWindow. This class used to create a new menu where you add the JMenuItems. It implements the radio button and shows the state of an item selected or deselected. It provides small window where the various types of choices are available.

JSplitPane This class used to divides the two components graphically like: top and button. JSlider This class provides a control to represent a numeric value by dragging the slider.ToggleButtonModel It extends the DefaultButtonModel and provides theToggleButton model. JScrollPane It provides the scrollable view components. JToggleButton It implements two state button that means selected or deselected. left and right. JToggleButton. JTextField It provides the facility to editing the text in a single line. JTable It provides the user interface component and represents the two dimensional data. JTextArea It provides the multi line plain text area. JTree It shows the data in a hierarchical the content to scroll this. JToolBar It provides set of command buttons icons that performs the different actions or controls. JToolBar. JSeparator This class use the separator among the components. JTabbedPane This class provides the tab component through which you can switch from one component to another component regarding to the specific tab button by clicking on that. JTree. JToolTip It shows the tool tips related to it's components. JTextPane This class provides the component like JTexArea for multiple lines text with more capabalities.DynamicUtilTreeNode This extends the DefaultMutableTreeNode and create .Separator It provides the tool bar separator.

This class controls the key events on the keyboard for the equivalent device. It has menu selection hierarchy. position or orientation. type. It extends window and shows the any location or area on the desktop. It gives you about the underlying information. It does not allows the any selection. This class conducts the sorting objects according to their size. It provides the dramatically changes in the component like frame related to the graphics for the application. column header etc. It implements the LayoutManager and manage the components like: scroll bar. It couldn't any title bar and window management buttons. It represents the order list of size and it's . It cleanups all the rights when the stream is closed. row header. The layout manager arrange the components.UIResource SizeRequirements SizeSequence children nodes. This class is used to monitoring the progress of any operation to be done.JTree. It calculates the size and positions of components. Through this the application can be done very efficient and easier. This class manage and override the repaint requests. It extends the ScrollPaneLayout and implements the UIResource. This class creates a progress monitor to monitor the progress of reading input from the input stream.EmptySelectionModel JViewPort JWindow KeyStroke LayoutFocusTraversalPolicy LookAndFeel MenuSelectionManager OverlayLayout ProgressMonitor ProgressMonitorInputStream RepaintManager ScrollPaneLayout ScrollPaneLayout.

This class creates a Input Map through it's createValue() method.ProxyLazyValue UIManager UIManager.LazyInputMap UIDefaults. It manages the all tool tips. It implements the LayoutManager and defines the policy for the layout. used for getting information about all the look and feels installed with the softwaredevelopment kit. This class is used to create a lazy value which is used to delay loading of the class to create instance for that. . Example of binding of key is array of pressing key information (e. The following Exceptions and it's description to be used by the Java swing.LookAndFeelInfo ViewportLayout positions.g. This class has track of the current look and feel details. This is the nested class of UIManager class i. Actions perform the predefined rate. The array of key after binding is passed to the constructor of this.SwingUtilities Timer ToolTipManager UIDefaults UIDefaults. ctrl + c or alt + f). It extends the Hashtable and you set/get the value with the help of UIManager. This class has utilities methods for swing. Exception Descriptions This exception occurred when the look UnsupportedLookAndFeelException and feel classes are not supported to user's system.e.

Container cpane=o. Gets the menu for this frame. create JFrame object 2. add component to content pane. Creates a new frame with the specified title. Steps: 1. Constructor JFrame ( ) JFrame (String title) Method void add (Component c) Description Creates a new frame with no title. JMenuBar getJMenuBar ( ) void pack ( ) .JFrame • • • Package:javax. Description Adds the specified component to the frame.add(<Somecomponent>). Adjusts the size of the frame to fit the components added to it. Example: JFrame o=new JFrame(). Get content pane 3. Cpane.getContentPane(). The components added to frame’s content pane instead of adding them directly to the frame itself.swing JFrame is an abstract class It is heavyweight component The content pane was introduced in swing to deal with the complexities which are involved in making heavyweight and lightweight component work together.

Always specify JFrame. void setDefaultCloseOperation void setIconImage (Icon image) void setLayout (LayoutManager layout) void setLocation (int x. Sets the icon displayed when the frame is minimized. Sets whether or not the size of the frame can be changed by the user. Sets the action taken when the user closes the frame.EXIT ON CLOSE. The default setting is true (the frame can be resized). 0. Sets the size of the frame to the specified width and height. int y) void setLocationRelativeTo (Component c) void setResizeable (boolean value) void setSize (int width. int height) . Sets the x and y position of the frame on-screen. The default is the BorderLayout manager. Centers the frame onscreen if the parameter is null. Removes the specified component from the frame. The top-left corner of the screen is 0. Sets the layout manager used to control how components are arranged when the frame is displayed.void remove (Component c) void remove (Component c) Removes the specified component from the frame.

An intermediate JPanel object is made part of content pane using setContentPane() method of JFrame class Example: JFrame o=new JFrame(). Create JPanel object 3. Add all component to the JPanel object by using add() method 4. The default setting is true (the border is shown). Description Shows or hides the button's border. Create JFrame object 2. o. JPanel pnl=new JPanel(). Creates a new button with the specified text. The default setting is true (the background is filled in).swing. Specifies whether or not the button's background should be filled or left empty.void setJMenuBar(JMenuBarMenu) Sets the menu for this frame. JPanel Package: javax. pnl.setContentPane(pnl). • JButton (String text) Method void setBorderPainted (boolean value) void setContentAreaFilled (boolean value) . Constructor Description JButton ( ) Creates a new button with no initial text.add(<Somecomponent>).JPanel • It used to group components within one area of an applet or a frame Steps: 1.

add(<some component>). Sets the text displayed by the button. which causes the border to get thicker when the mouse moves over the button. Sets the tooltip text that's displayed if the user lets the mouse rest over the button.* • Like JFrame the components are first added to the contentpane Example: Container cpane=this. Returns the text displayed by the button. Painting in Swing and AWT . Enables or disables the rollover effect. Shows or hides the button.getContentPane(). The default setting is true (enabled).setLayout(<LayoutObject>).swing. The default setting is true (the button is visible). cpane. cpane. • Package:javax. Enables or disables the button. String getText () void setEnabled (boolean value) void setRolloverEnabled (boolean value) void setText (String text) void setToolTipText (String text) void setVisible (boolean value) JApplet • Swing applet represent by class JApplet. The default setting is true (rollover effect enabled).doClick ( ) Triggers an action event for the button as if the user clicked it.

Instead of using paint() method . Set or get the applet's layered void pane. void setGlassPane(Component) Set or get the applet's glass pane. You can use the frame's setLayeredPane(JLayeredPane) layered pane to put components JLayeredPane getLayeredPane() on top of or behind other components. set. the glass pane. The root pane manages the void setRootPane(JRootPane) interior of the applet including the JRootPane getRootPane() content pane. The JApplet API Method Purpose Set or get the applet's content void pane. . or get the applet's root JRootPane createRootPane() pane. The content pane contains setContentPane(Container) the applet's visible GUI Container getContentPane() components and should be opaque.Swing itself uses paint() method to draw the border around the component as well as to draw any child component inside the component and other task. Create. You can use the glass pane to Component getGlassPane() intercept mouse swing swing we can use paintComponet() method. Set or get the applet's menu bar to void setJMenuBar(JMenuBar) manage a set of menus for the JMenuBar getJMenuBar() frame. and so on.

it's supported with a JMenuBar object.probably the most interesting lauered pane are content pane and menu bar Content pane: The content pane was introduced in swing to deal with the complexities which are involved in making heavyweight and lightweight component work where most of action takes place. From programmer’s point of view . Layered pane: The layered pane of class JLayeredPane. .because you’re expected to add them to the content pane in the JRootPane object The root pane and its member are all consider being fundamental in Swing Container Design.which display right above the content pane.Note: Although you can add component directly to JFrame or JApplet. JRootpane GlassPane LayeredPane Glass pane: The Glass pane is used to draw over an area that already contains some components.A glass pane also be used to catch mouse events. The components added to frame’s content pane instead of adding them directly to the frame itself. dialog boxes and so on. JMenubar: If you have menu bar in you’ll get an error unless you turn off some error checking first. There are specific layers to which you have access that display menus when they’re opened.