Swing

OverlayLayout Manager Example Java Swing

We have seen earlier BoxLayout manager where the components are set in X and Y axes directions. Now let us go for another exclusive Swing manager, OverlayLayout. As the name indicates, one component can be placed on the top of the another. When different sizes are given, the components can…

Java Swing Components (Advanced AWT)

Following links give you the Swing components – programs, output screen and explanation. Swing basics 1. Java JFC Swing Introduction 2. Swing Overview Are you interested in Swing – Input and Output? 1. Output: Swing JOptionPane – Displaying Message 2. Input: Swing JOptionPane – Taking User Input Total 4 programs…

JScrollPane Example Java Swing

JScrollPane scrolls to view the contents of the component added to it. Scrollbars are used to scroll the contents horizontally and vertically. From JDK 1.4, new methods for mouse wheel movements are added like processMouseWheelEvent(MouseWheelEvent) etc. The mouse wheel can be used to enlarge a photo by rotating the wheel…

JTree Example Java Swing

JTree is a swing component that can be used to display a hierarchy of data like Window Explorer. Each element in the tree becomes a node. For a node another node can be added thus constructing a tree. Nodes are expandable and collapsible. Collapsible nature hides some nodes, thus the…

ProgressMonitor Example Java Swing

ProgressMonitor monitors the progress of the operation. Displays in percentage of completion of the operation. Example on ProgressMonitor

Output screen on ProgressMonitor Example

Two methods of ProgressMonitor are used: isCanceled() and setProgress().

BoxLayout Manager Example Java Swing

BoxLayout lays out the components in a horizontal or vertical line. An axis – either BoxLayout.X-AXIS or BoxLayout.Y-AXIS is specified at the time of construction and determines the orientation of the components. Components laid out along the x-axis are laid out horizontally, and components laid out along the y-axis are…

JColorChooser Example Java Swing

Swing JColorChooser gets your own color palette. The color you selected either with RGB or HSB style can be applied to any Swing component. In the program,it is applied to Container (indirectly to JFrame). Example on JColorChooser

Output screen on JColorChooser Example clr = JColorChooser.showDialog(this, “Choose Your Color”, Color.green);…

JDesktopPane Example Java Swing

JDesktopPane – Multiple Document Interface (MDI) Many of today’s applications use a multiple document interface (MDI) [i.e., a main window (often called the parent window) containing other windows (often called child windows)] to manage several open documents that are being processed in parallel. Many commercial Window products such as Microsoft…

JMenu Example Java Swing

JMenu program comprises of menu bar, menus, menu items and separators etc. JMenuItem can be added with images, check boxes, combo boxes etc. Some objects in this program are declared final and if not they cannot be accessed from inner classes. Example on JMenu

For a similar AWT Menus…

JSlider Example Java Swing

JSliders enable the user to select from a range of integer values. Class JSlider inherits form JComponent. The following program creates a horizontal JSlider with tick marks and the thumb that allows the user to select a value. JSliders can be customized so that they can display major tick marks,…

JList Multiple Selection Example Java Swing

In the previous program, you have seen JList with single selection. Now let us go for JList Multiple Selection. In the following JList Multiple Selection example, user’s multiple selected items are displayed in JOptionPane using showMessageDialog() method.

places.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); The above statement allows the list for multiple selections. By clicking…

JList Single Selection Example Java Swing

A list displays a series of items from which the user may select one or more items. Lists are created with class JList, which inherits from class JComponent. Class JList supports both single-selection lists (i.e., lists that allow only one item to be selected at a time) and multiple-selection lists…

JComboBox Example Java Swing

A JComboBox (sometimes called a drop-down list) provides a list of items from which the user can make a selection. Combo boxes are implemented with class JComboBox, which inherits from class JComponent. JComboBox generates ItemEvent like JCheckBox and JRadioButton. Its counterpart in AWT is Choice. In the following JComboBox example…

JRadioButton and Button Group Example Java

This is an exclusive program on JRadioButton and ButtonGroup. To group six radio buttons, two objects of ButtonGroup are created and for each group three radio buttons are added. User’s selection is displayed using JOptionPane showMessageDialog() method. There is no counterpart class for this class in java.awt package; it is…

JCheckBox Example Java Swing

Following is an exclusive program on JCheckBox. The text font in a text field is changed as per the JCheckBox selected by the user. Four JCheckBox objects are created for font name, font style, font size and to close the JFrame. The counterpart of JCheckBox in java.awt is Checkbox. Example…