Augment Java Swing Components with JClass Elements
Java Swing provides multiple elements and controls “right out of the box” to create interactive user interfaces for thick Java clients that run on any of several platforms. However, certain controls that developers might want to add to their applications aren’t available, especially for earlier versions of Java.
JClass Elements is a broad collection of GUI components and utility classes designed to augment Swing’s basic offering. These additions include a variety of form and layout controls. In this article, we will cover the form controls that are included in JClass Elements.
A JCCheckBoxList is similar in function to the default Swing component JList (and, in fact, extends it), but instead adds a checkbox that appears to the left of the list items it displays. This component allows you to provide an alternate visual metaphor for indicating which items are selected. This paradigm makes selecting multiple items from the list simpler and will be familiar to end users from their previous experience with HTML-based forms with multiple checkboxes. This implementation uses ListSelectionEvent and ListSelectionListener to let you track the list items that have been selected as the user interacts with the form.
The JClass JCCheckBoxList vs. the standard Swing JList
JCMultiSelectList is another component similar to JList except that, instead of one list, two lists appear in the component’s GUI, providing a “slosh bucket” style component to transfer items between the two lists.
An example of JClass JCMultiSelectList
There are four buttons between the two lists that move items back and forth. The left-hand list contains non-selected items and the right-hand list contains the selected items. In the context of a JCMultiSelectList, if an item is highlighted, that indicates it is an element that will be moved from one list to the other when a button to move that individual element is clicked.
Besides providing a visual division of list items into the two columns (selected and non-selected), there are numerous methods for dealing with the values and indices of a set of selected values.
JCSpinBox and JCSpinNumberBox
The JClass spin box components let the user select a number or an element in a list by clicking on up or down arrows. You can use a JCSpinBox to spin through a list of Objects (as long as the required editors and renderers exist, or have provided them), or use a JCSpinNumberBox, which can display any numeric object. This spin box implementation follows the standard DataModel abstractions ComboBoxModel and the ListDataModel, allowing you to treat it as you would other form elements you’re using. The JCSpinNumberBox exposes properties to provide constraints, formatting and the increment of the spinner.
Examples of JCSpinBox
JCFontChooserPane provides a pane of controls designed to allow a user to manipulate and select a font. It is suitable for use in a tab pane or a dialog window. JCFontChooserPane includes a preview area with sample text.
JCFontChooserBar provides a pane of controls designed to allow a user to manipulate and select a font. It is suitable for use in a JToolbar, a container that groups several components (usually buttons with icons) into a row or column. Like the standard Swing components, JCFontChooserBar provides the optional use of a Tool Tip.
An Example of JCFontChooserBar and JCFontChooserPane
JCDateChooser and JCPopupCalendar
JCDateChooser is a component that displays controls for selecting a calendar date in one of four different forms. Each one displays the days of the month in the familiar form of a calendar, but varies the way the month and year are displayed. Display styles include various combinations of spinners and pop downs to select the month and year as well as “read only” version of the interface to simply show the date in a static manner.
Variations of Calendar Selectors
JCPopupCalendar is a component that allows you to edit a date and time using a drop-down calendar. In its editable form, the popup calendar displays a text field with a button next to it.
Pushing on the button pops down a calendar from which a date and time can be selected. By default, the calendar has spin boxes for the year, month, and time along with a table displaying the days of the month. The day table updates each time the year and month are changed to reflect the correct number of days. The time spin box allows editing of the hour, minute, second, and meridiem.
JCPopupCalendar is an extension of JComboBox. Instead of selecting an item from a drop- down list, the user selects a date-and-time value using a popup calendar editor.
JCPopupCalendar uses a JFormattedTextField that is configured to edit dates as its text editor. The text editor's value is kept in-sync with the popup calendar editor's value, so changing one will automatically update the other. As with JComboBox, JCPopupCalendar is non-editable by default. In this case, the text field is replaced with a button which, when selected, activates the popup calendar editor. The popup calendar editor can still change the value in the non-editable case.
A sample popup calendar
The JCElement calendar components allow you to specify bounds for minimum and maximum dates, provide utility methods such as determining if a given year is a leap year or to retrieve the day of the week, and also allows certain days to be marked as “special days.” This final option allows particular days or groups of days to be handled based on specific business rules. For instance, some businesses that are open on the weekend close on Mondays. Therefore, there is utility in being able to lump all Mondays together and classify them as days when the store is closed.
In addition to all these input controls, there are a variety of layout controls for trees, sortable tables, splash screens, and wizard panels. We will discuss those controls in a future post.
Leverage JClass form Controls with our new and improved JClass Elements software. Quest customers with an active JClass maintenance agreement can upgrade to Scout Solutions version of JClass Elements for free. With the purchase of a support plan, you will receive access to our expert JClass support team. Save yourself the trouble of upgrading to a new software, and make it easier by choosing JClass. Get in touch with us to claim your free upgrade, or to purchase continued support for your JClass software.