Java Tutorial

by Dinesh Thakur Category: Swing

Every swing component that is a subclass of JComponent can have a border. A border is a decorative element that virtually group components by drawing a line around them. By default, a component does not have a border.

 
by Dinesh Thakur Category: Swing

The SpringLayout layout manager is for a GUI's components to maintain their position relative to container edges or the edges of the other components after the GUI is resized. The SpringLayout layout manager lays out its container components according to a set of constraints specified by the user. Each constraint represented by a Spring object, controls the vertical or horizontal distance between two component edges. The edges can belong to the container itself or to any child of the container.

 
by Dinesh Thakur Category: Swing

Glue is an invisible component which is similar to a strut but it pushes the components as far away from each other as possible within the bounds of the box itself. You create an invisible component that represents Glue by calling the createGl ue () method for a Box object For example: The statements

 
by Dinesh Thakur Category: Swing

A rigid area filler is similar to pair of struts. It is an invisible component with a specific width and height. It can be created using the static method

 
by Dinesh Thakur Category: Swing

A strut is a fixed width invisible component that forces a certain amount of space between components. You can create a strut by calling the createHorizontalStrut () or createVerticalStrut () method depending upon what type of strut you want to create. The static method

 
by Dinesh Thakur Category: Swing

Although you can use the BoxLayou t directly, it is much more convenient to use javax.swing.BoxContainer class which has a built in BoxLayout layout manager. This class has some additional facilities that provide more flexibility in the arrangement of components than is provided by other containers such as JPanel object.

 
by Dinesh Thakur Category: Swing

The BoxLayout layout manager is similar to FlowLayout in that, the components are placed in the order in which they are added and each component gets to have its own size. But unlike FlowLayout, the BoxLayout layout manager arranges components in either a single row or a single column. In other words, the components you add to BoxLayout are added vertically from top to bottom or horizontally from left to right. In BoxLayout, components will not continue on the next line or columns when there is insufficient room. The components that are out of range will not be shown. This layout manager is useful for creating toolbars or vertical button bars.

 
by Dinesh Thakur Category: Swing

A panel in swing is similar to Panel in AWT, is a lightweight container that is designed to group a set of components, including other panels. It is visually represented as window that does not contain a title bar, menu bar or border. It is simplest of all the containers. Its default layout manager is FlowLayout.

 
by Dinesh Thakur Category: Swing

A scrolling pane is a container that can be used to hold any component that can be scrolled. By default, the list and textarea component do not scroll automatically when number of items in the list or text area component go beyond the displayed area. So to make these components scroll, you must insert them into the scrollpane. After you create a scrollpane containing a component (list or textarea), the scrolling pane should be added to the container in place of that component. A scrolling pane can be created by instantiating the JScrollPane class.

 
by Dinesh Thakur Category: Swing

A list components allows user to select a single or multiple items from a given list of items by clicking on each. By default, a user can select multiple items, however it is also possible to create a list from which user can choose only a single item.

 
by Dinesh Thakur Category: Swing

As a group of radio buttons, a drop-down list is a form of forcing the user to select only one element of a group of possibilities. However, it is a more compact way to do this, and is easier to change the elements of the list without surprising the user.

 
by Dinesh Thakur Category: Swing

The radiobutton component is a two state button which can either be selected or not selected, similar to a checkbox component. However, unlike checkboxes, the radiobuttons are associated with a group and only one radiobutton in a group can be selected. When the radiobutton in the group is selected, any other previously selected radiobutton in the group is deselected. The JRadioButton class is a subclass of JToggleButton which is further a subclass of AbstractButton.

 
by Dinesh Thakur Category: Swing

A checkbox component in Swing is similar to checkbox component in AWT. A check box is a control that consists of a combination of a small box and a label. The label provides the description of the box with which it is associated. It is a two-state control having states true (checked) and false (unchecked). The state of a checkbox can be changed by clicking on it. A checkbox is an object of JCheckBox class.

 
by Dinesh Thakur Category: Swing

A Textfield is a component used for displaying, inputting and editing a single line of plain text. We can create text field by creating an instance of JTextField class. The JTextComponent is a superclass of JTextField that provides common set of methods used by JTextfield.

 
by Dinesh Thakur Category: Swing

The Buttons component in Swing is similar to the Button component in AWT except that it can contain text, image or both. It can be created by instantiating the JButton class. The JButton class is a subclass of AbstractButton class.

To the text on the face of an object is called JButton button label. Having more than one JButton object with the same tag makes the JButton objects are ambiguous for the user (each button label must be unique).

 
by Dinesh Thakur Category: Swing

The PasswordField is a special kind of textfield. It is a single line textfield used for accepting passwords without displaying the characters typed in. Each typed character is represented by an echo character typically an astriek (*). To create a PasswordField component, instantiate the JpasswordField class.

 
by Dinesh Thakur Category: Swing

The TextArea component in swing is similar to the TextArea component in AWT as it allows to display and edit multiple lines of plaintext. But unlike TextArea component in AWT, if all the text cannot be displayed in the available space in the component, scrollbars are not automatically added. In order to add scrollbars, you must insert it into a ScrollPane.

 
by Dinesh Thakur Category: Swing

JLabel component in swing is similar to label in AWT except that it may contain uneditable text, an image or both. We can create label by creating an instance of JLabel class.

 
by Dinesh Thakur Category: Swing

Another way of creating an application window is by defining a new class that extends the JFrame class. The new class will inherit fields and methods from the JFrame class. This technique is a preferred style for creating GUI applications.

 
by Dinesh Thakur Category: Swing

In order to add a component to a container, first create an instance of the desired component and then call the add () method of the Container class to add it to a window. The add() method has many forms and one of these is,

 


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.