JClass Elements - Layout Controls
Java Swing provides many components to support thick Java clients right “out of the box.” JClass Elements is a broad collection of GUI components and utility classes designed to augment Swing’s basic offering. These include components for managing how applications lay out their input controls as well as their help panels and wizards.
In Java GUIs, layout managers are used to arrange components like text inputs and drop-downs in a particular way. JCElements provides a number of layout managers of its own, including: one that allows applications to lay out input fields and their associated labels in a vertical arrangement; another that allows applications to grow or shrink proportionally in an elastic manner; and finally, one that creates an intelligent grid layout of components in rows and columns. Additionally, there are components to create borders and reserve screen “real estate” to control how the visible elements are arranged and spaced out.
Vertically Aligned Layouts
JCAlignLayout is a layout manager that provides a simple way to lay out a vertically arranged group of control components, each with an associated label (or other component) placed to its left. Although its intended use is one with labels in the first column, JCAlignLayout lets you place any component in any column.
A form using JCAlignLayout.
JCElasticLayout is a layout manager that supports horizontal or vertical displays of components that implement (or have a constraint object that implements) the JCElastic interface, which designates a relative measure of “stretchiness” for a given component’s dimensions.
If the container is bigger than the preferred size of all the components, then the extra space is divided up between the components that are “elastic” in the direction of the layout’s orientation. The extra space is allocated to each of the components with respect to their relative “elasticity,” or how much they change their size as defined in the JCElastic interface. The effect is to keep components relatively equidistant and (depending on a given component's elasticity) proportional to each other.
JCRowLayout and JCColumnLayout are subclasses of JCElasticLayout that enable layouts in a single row or column respectively while JCSpring has independently settable elasticity parameters for both the horizontal and vertical directions.
Within an elastic layout you can use a container called JCBox to arrange components in a single row or column. Meanwhile, a JCBrace functions is to reserve space as a way of controlling the layout of the visible components without itself being visible.
JCGridLayout improves on the subclass of the built-in class GridLayout by sizing cells more intelligently. The component lays out a grid of rows and columns based on the attributes of the individual rows and columns. Whereas GridLayout uses the widest and tallest child to size each cell, JCGridLayout uses the widest element in a column to set the width of that column, and the tallest element in a row to set the height of that row.
A comparison of JCGridLayout and GridLayout.
JCBorder can be used with any layout manager. It allows a border to be placed anywhere, not just around a component. You draw a border by overriding the component’s paint method and calling the draw method of JCBorder. Its parameters allow you to specify a style, size, shadow, and placement relative to its parent.
Multiple Document Interfaces
Multiple document windows are used when multiple views of your data may be required or when multiple forms need to be simultaneously present in a window. An example of an application that uses such a model is an Integrated Development Environments (IDEs), which developers use to write code. In such an application, a Java coder might want to look at the text of multiple .java files as well as the attributes about ancillary files such as .properties files, which could have their own specialized editors (i.e., one used for localization).
A Multiple Document Interface (MDI) model is a common way of organizing and presenting information in windows-style environments. The MDI model makes it possible to arrange multiple child windows inside a parent window, such as multiple files in a text editor, or multiple charts in one frame. In effect, the parent window becomes the desktop within which the children operate.
In Java, the container typically used to hold a multiple-document interface is a JDesktopPane, which you would put into the content pane of a JFrame and then add JInternalFrames as needed for your document windows. The JClass Elements components JCMDIPane and JCMDIFrame augment the functionality of JDesktopPane and JInternalFrame, respectively.
The JClass versions optimize space by managing the active window’s main menu bar, while providing the standard window-management options. JClass Elements's multiple document JCMDIPane interface component extends Swing's JDesktopPane view to provide the following standard MDI features:
- True maximization—instead of keeping two menu bars when an internal pane is maximized, JCMDIPane optimizes screen real estate by placing menus on the desktop's menu bar.
- Automatic addition of a “Windows” menu containing two sections.
- An upper section with options that allow the selection of a window tiling algorithm (cascade, tile horizontally, or tile vertically), the minimizing/maximizing of a selected frame, and the rearranging of icons of the minimized frames.
- A lower section that allows the switching of focus to any internal frame by selecting its name from a menu.
- The ability to un-maximize or close maximized frames.
A JFrame containing a JCMDIPane and multiple JCMDIFrames
Wizards are a familiar paradigm for user interfaces that walk end users through a series of steps to complete a task, such as the installation of software. JCWizard and JCSplitWizard let you create and manage a wizard-style group of dialogs by supplying informative events and special page components with standard buttons.
JCWizard supplies standard “Next,” “Back,” “Finish,” “Cancel” and “Help” buttons that are characteristic of Wizard dialogs. You may provide instructions for the end user on each page and define the actions corresponding to the choices made by the end user. Add a JCWizardListener to your wizard dialogs to invoke the actions that each page needs to perform.
JCSplitWizard creates a split-Wizard layout, which allows for one page to be created with multiple panels, rather than multiple pages with one panel.
A sample Wizard page
A sample split-Wizard page
Providing help to end users is important for the ease of use of applications. JClass simplifies the addition of help to an application with JCHTMLPane and JCHelpPane. Pass an HTML-encoded file to an instance of JCHTMLPane and you have a mini browser. JCHelpPane supports up to three instances of JCHTMLPane and provides basic navigation buttons, allowing you to implement a simple HTML-based help system. The left pane functions as a table of contents, and the right pane shows the help pages.
A demo of JCHTMLPane and its HTML rendering capabilities
Splash Screens and Exit Frames
A splash screen is an image that appears while an application is loading. It serves both as an indication that the program is being loaded and as a place to put notices, such as copyrights, version, or release number. Once the application is ready to run, it notifies to the JCSplashScreen instance so it may be closed. You may also use a JCExitFrame to manually close a splash screen.
The JCExitFrame is a frame that responds to window-closing events either by exiting or by becoming invisible.
In addition to all these layout controls, there are a variety of form input and data display controls included in JCElements. We discussed these controls in previous posts, including enhanced select lists trees and choosers as well as sortable tables and tree controls.
Upgrade JClass Elements for Free with Scout Solutions
Upgrade your current version of JClass Elements for free with Scout Solutions and receive ongoing support. Unlike Python or other softwares, JClass offers ongoing support and customer service. The support team at Scout Solutions can help address any JClass questions or issues quickly.
For a limited time, we are offering a free JClass upgrade for current Quest JClass customers with an active support agreement. If you don't have a support agreement, you can purchase one through Scout Solutions. Save yourself the trouble of moving from JClass to another program and renew your license through Scout Solutions. Learn more, or contact us to claim your free upgrade.