JFormDesignerDoc-5 0
JFormDesignerDoc-5 0
JFormDesignerDoc-5 0
0 Documentation
Contents
1 2 3 Introduction .......................................................................................................................................... 2 What's New .......................................................................................................................................... 3 User Interface ....................................................................................................................................... 7 3.1 Menus ............................................................................................................................................ 8 3.2 Toolbars ........................................................................................................................................ 11 3.3 Design View .................................................................................................................................. 12 3.3.1 Headers .................................................................................................................................. 14 3.3.2 In-place-editing ........................................................................................................................ 17 3.3.3 Keyboard Navigation ................................................................................................................. 17 3.3.4 Menu Designer ......................................................................................................................... 17 3.3.5 Button Groups .......................................................................................................................... 19 3.3.6 JTabbedPane ............................................................................................................................ 20 3.3.7 Events ..................................................................................................................................... 21 3.4 Palette .......................................................................................................................................... 23 3.5 Structure View ............................................................................................................................... 26 3.6 Properties View .............................................................................................................................. 27 3.6.1 Layout Manager Properties ......................................................................................................... 28 3.6.2 Layout Constraints Properties ..................................................................................................... 29 3.6.3 Client Properties ....................................................................................................................... 29 3.6.4 Code Generation Properties ........................................................................................................ 30 3.6.5 Property Editors ........................................................................................................................ 32 3.7 Bindings View ................................................................................................................................ 42 3.8 Error Log View ............................................................................................................................... 43 4 Localization ......................................................................................................................................... 44 5 Beans Binding (JSR 295) ...................................................................................................................... 50 6 Projects .............................................................................................................................................. 55 7 Preferences ......................................................................................................................................... 57 8 IDE Integrations .................................................................................................................................. 74 8.1 Eclipse plug-in ............................................................................................................................... 75 8.2 IntelliJ IDEA plug-in ........................................................................................................................ 79 8.3 JBuilder plug-in .............................................................................................................................. 82 9 Layout Managers ................................................................................................................................. 85 9.1 BorderLayout ................................................................................................................................. 87 9.2 BoxLayout ..................................................................................................................................... 88 9.3 CardLayout .................................................................................................................................... 89 9.4 FlowLayout .................................................................................................................................... 90 9.5 FormLayout (JGoodies) ................................................................................................................... 91 9.5.1 Column/Row Templates ............................................................................................................. 92 9.5.2 Column/Row Groups ................................................................................................................. 93 9.6 GridBagLayout ............................................................................................................................... 96 9.7 GridLayout .................................................................................................................................... 99 9.8 GroupLayout (Free Design) ............................................................................................................ 100 9.9 HorizontalLayout (SwingX) ............................................................................................................. 104 9.10 IntelliJ IDEA GridLayout ............................................................................................................... 105 9.11 null Layout ................................................................................................................................. 107 9.12 TableLayout ............................................................................................................................... 109 9.13 VerticalLayout (SwingX) .............................................................................................................. 111 10 Java Code Generator ........................................................................................................................ 112 10.1 Nested Classes ........................................................................................................................... 113 10.2 Code Templates .......................................................................................................................... 115 11 Command Line Tool .......................................................................................................................... 116 12 Runtime Library ............................................................................................................................... 119 13 JavaBeans ....................................................................................................................................... 121 14 Annotations ..................................................................................................................................... 124 15 JGoodies Forms & Looks .................................................................................................................... 126 16 Examples & Redistributables .............................................................................................................. 127
-1-
Introduction
JFormDesigner is a professional GUI designer for Java Swing user interfaces. Its outstanding support for JGoodies FormLayout, GroupLayout (Free Design), TableLayout and GridBagLayout makes it easy to create professional looking forms.
Editions
JFormDesigner is available in four editions: as stand-alone application and as IDE plug-ins for Eclipse, IntelliJ IDEA and JBuilder. This documentation covers all editions. If there are functional differences between the editions, then they are marked with: Stand-alone, Eclipse plug-in, IntelliJ IDEA plug-in, JBuilder plug-in or IDE plug-ins.
Key features
Easy and intuitive to use, powerful and productive IDE plug-ins and stand-alone application GroupLayout (Free Design) support JGoodies FormLayout and TableLayout support Advanced GridBagLayout support Column and row headers Localization support Beans Binding (JSR 295) support BeanInfo Annotations Java code generator or runtime library Generation of nested classes
-2-
JFormDesigner 5 introduces more than 40 new features and enhancements. This topic describes some of the significant or more interesting changes. Please have a look at the change log for a complete list of changes.
Beans Binding Using Beans Binding (JSR 295) helps you to keep UI state and model in sync. It drastically reduces the amount of listener code that is usually necessary. (JSR 295) support
The new Bindings view gives a good overview of all bindings in a form.
BeanInfo Annotations
The new @BeanInfo and @PropertyDesc annotations make it very easy to specify BeanInfo information directly in the custom component. Its no longer necessary to implement extra BeanInfo classes. This drastically reduces time and code needed to create BeanInfo information.
@BeanInfo(isContainer=true, categories={ @Category(name="Gradient Properties", properties={"direction", "magnitude"}) }) public class JGradientPanel extends JPanel { @PropertyDesc(displayName="direction (to)", preferred=true, enumValues={ @Enum(name="NORTH", intValue=SwingConstants.NORTH, code="SwingConstants.NORTH"), @Enum(name="EAST", intValue=SwingConstants.EAST, code="SwingConstants.EAST"), @Enum(name="SOUTH", intValue=SwingConstants.SOUTH, code="SwingConstants.SOUTH"), @Enum(name="WEST", intValue=SwingConstants.WEST, code="SwingConstants.WEST") }, imports=SwingConstants.class) public int getDirection() { return direction; } @PropertyDesc(displayName="magnitude (in %)", preferred=true) public int getMagnitude() { return magnitude; } }
-3-
The Properties view has been improved in many ways: Ability to filter properties. Introduced categories to group properties. Added Bindings and Events categories. Group by Category, Group by Defining Type and Alphabetical commands introduced to allow grouping of bean properties into categories (normal, expert, read-only and custom categories); into defining types (e.g. JTextField, JTextComponent, JComponent, Container, Component); or alphabetically. Support for custom categories specified in PropertyDescriptor of BeanInfo. Show changed properties even if containing category is collapsed. Moved Code Generation properties from its own tab to a new category. Show number of (set) properties per category. Removed grid lines to show more properties.
The Properties view now supports searching for property names. Select the Show Filter ( ) toolbar button to show the search text field below the toolbar, where you can enter your filter criteria.
Events have been moved from the Structure view to the new Events category in the Properties view. Here you can also add, edit or remove event handlers.
The Add Event Handler popup menu has been optimized to reduce the necessary clicks to add event handlers. Listeners that have only one method are now in the main popup menu instead of in its own submenu.
-4-
Similar to the other IDE plug-ins, the Eclipse plug-in now also has a Go to JFormDesigner form ( ) / Go to Java code ( ) command in its toolbar, which allows you to quickly switch from a Java editor to a JFormDesigner form editor and vice versa. Default key binding is Ctrl+Shift+D (Mac: Shift+Command+D).
Additionally there is a new New JFormDesigner form ( binding is Ctrl+Shift+V (Mac: Shift+Command+V). Styled text
JFormDesigner now uses styled text everywhere where useful. Styled text not only looks cool, it mainly helps you to better distinguish between main information and decoration.
Many settings from the global Preferences dialog are now also available per project. You can use project specify settings for JGoodies FormLayout, null Layout, Localization, Java Code Generator (including sub-pages) and Client Properties. IDE plug-ins: The pages are integrated into the IDE Project dialogs. The project specific settings are stored in the project files of the IDEs in their format. Stand-alone edition: The settings are stored in JFormDesigner project files (.jfdproj) and can be modified in the Project dialog.
The Choose Bean dialog has been improved in many ways: Camel-case pattern match finds classes with fewer keystrokes. E.g. DPB matches DatePickerBean. Highlights characters in list that match the filter pattern. Ability to disable JavaBean filter and to show matching interfaces in result. Displays additional information about matching classes: modifiers (as icon), class hierarchy (in tooltip), number of matching classes and used filter. Classpath Info link added, which shows the resolved classpath used by JFormDesigner.
Now you can change layout properties of a JScrollPane (in Properties view and using the context popup menu) even if its child is selected. No longer worry about JScrollPane selection. When clicking a JScrollPane in Design view, its child gets now selected, which is usually what you need. You can still select the JScrollPane in Structure view.
-5-
non-public JavaBeans
You can now use non-public JavaBeans and interfaces in Design view. Non-public JavaBeans must be in the same package as the form or a nested static class of the form class. Interfaces are not initialized in the generated Java code. You have to do this yourself before invoking initComponents(). JFormDesigner's new class loader technology automatically reloads custom components when they change. This is extremely useful when you develop custom beans. Simply edit your component, compile it and you see your changes immediately in JFormDesigner. The new class loader now can load custom beans compiled for Java 6+ while running JFormDesigner in a Java 5 VM (when the custom beans does not use Java 6+ API).
JGoodies FormLayout 1.3, which provides a new factory class com.jgoodies.forms.factories.CC for CellConstraints objects creation, is now supported.
The code generator can now automatically detect the version of your JGoodies Forms library JGoodies Forms version (forms.jar) in the classpath of your project and generate appropriate Java code. auto-detection GroupLayout The new Duplicate command allows you quick duplication of selected components. Properties for improvements empty space around components have been added to the GroupLayout constrains properties. Code formatter The Java code generator can now use the Eclipse code formatter to format generated code. Enable option "Use Eclipse code formatter" in Java Code Generator preferences. (Eclipse plug-in
only)
Custom Create Better support for custom creation of components (e.g. using factories) with new property Custom property Create (category Code Generation). When checked for a component, the JFormDesigner generates an empty method createUIComponents() where you can write your own component creation code. Improved IntelliJ IDEA and NetBeans form conversion The IntelliJ IDEA forms converter now supports nested forms and the Custom Create flag. The new option Form class extends top-level container changes the extends clause of the converted form to extend the top-level container, which is necessary for nested forms. The NetBeans forms converter now supports forms that use Swing Application Framework resource management.
Command-line If you have to localize many existing non-localized forms, then you can now use the command-line tool to quickly externalize many forms. localization
-6-
User Interface
The main window consists of the following areas: Main Menu: Located at the top of the window. Toolbar: Located below the main menu. Palette: Located at the left side of the window. Design View: Located at the center of the window. Structure View: Located at the upper right of the window. Properties View: Located at the lower right of the window. Bindings View: Located below the Design view. This view is not visible by default. Click the Show Bindings View button ( ) in the toolbar to make is visible. Error Log View: Located below the Design view. This view is not visible in the above screenshot.
-7-
3.1
Menus
You can invoke most commands from the main menu (at the top of the main frame) and the various context (right-click) menus.
Main Menu
The main menu is displayed at the top of the JFormDesigner main window of the stand-alone edition.
File menu New Project Open Project Reopen Project Project Properties Close Project New Form Open Form Reopen Form Close Close All Save Save As Save All Import Creates a new project. Opens an existing project. Displays a submenu of previously opened projects. Select a project to open it. Displays the project properties. Closes the active project. Creates a new form. Opens an existing form. Displays a submenu of previously opened forms. Select a form to open it. Closes the active form. Closes all open forms. Saves the active form and generates the Java source code for the form (if Java Code Generation is enabled in the Preferences). Saves the active form under another file name or location and generates the Java source code for the form (if Java Code Generation is enabled in the Preferences). Saves all open forms and generates the Java source code for the forms (if Java Code Generation is enabled in the Preferences). Imports NetBeans, IntelliJ IDEA or Abeille form files and creates new JFormDesigner forms. Use File > Save to save the new form in the same folder as the original form file. This also updates the .java file. Exits JFormDesigner. Mac: this item is in the JFormDesigner application menu.
Exit Edit menu Undo Redo Cut Copy Paste Rename Delete
Reverses your most recent editing action. Re-applies the editing action that has most recently been reversed by the Undo action. Cuts the selected components to the clipboard. Copies the selected components to the clipboard. Pastes the components in the clipboard to the selected container of the active form. Renames the selected component. Deletes the selected components.
-8-
View menu Show Diagonals Squint Test Shows diagonals. Simulates evaluating a graphic layout by squinting your eyes. This tests legibility and whether the overall layout is a strong, clear layout. You can change the squint intensity in the Preferences. Refresh the Design view of the active form. Reloads all classes used by the form and recreates the form preview shown in the Design view. You can use this command, if you changed the code of a component used in the form to reload the component classes. But usually this is not necessary because JFormDesigner automatically reloads component classes.
Refresh Designer
Form menu Test Form Tests the active form. Creates live instances of the form in a new window. You can close that window by pressing the Esc key when the window has the focus. If your form contains more than one top-level component, use the drop-down menu in the toolbar to test another component. Edit localization settings, resource bundle strings, create new locales or delete locales. Creates a new locale. Deletes an existing locale. Moves strings to a resource bundle for localization. Use this command to start localizing existing forms. Moves strings from a resource bundle into the form and remove the strings from the resource bundle. Generates the Java code for the active form. Usually it's not necessary to use this command because when you save a form, the Java code will be also generated.
Localize New Locale Delete Locale Externalize Strings Internalize Strings Generate Java Code
Window menu Activate Designer Activate Structure Activate Properties Activate Bindings Activate Error Log Next Form Previous Form Preferences Help menu Help Contents What's New Tip of the Day Register License Check for Updates About Displays help topics. Displays what's new in the current release. Displays a list of interesting productivity features. Activates your license. Displays information about your license. Checks whether a newer version of JFormDesigner is available. Displays information about JFormDesigner and the system properties. Mac: this item is in the JFormDesigner application menu. Activates the Design view. Activates the Structure view. Activates the Properties view. Activates the Bindings view. By default, the Bindings view is not visible. Activates the Error Log view. By default, the Error Log view is not visible. It automatically appears if an error occurs. Activates the next form. Activates the previous form. Opens the Preferences dialog. Mac: this item is in the JFormDesigner application menu.
-9-
Context menus
Context menus appear when you're right-click on a particular component or control. Design view context menu: Properties view context menu:
- 10 -
3.2
Toolbars
Main Toolbar
This is the toolbar of JFormDesigner stand-alone edition. Many of the commands are also used in the toolbars of the IDE plug-ins.
New Project Open Project Project Properties New Form Open Form Save Save All Undo Redo Cut Copy Paste Delete Test Form
Creates a new project. Opens an existing project. Displays the project properties. Creates a new form. Opens an existing form. Saves the active form and generates the Java source code for the form (if Java Code Generation is enabled in the Preferences). Saves all open forms and generates the Java source code for the forms (if Java Code Generation is enabled in the Preferences). Reverses your most recent editing action. Re-applies the editing action that has most recently been reversed by the Undo action. Cuts the selected components to the clipboard. Copies the selected components to the clipboard. Pastes the components in the clipboard to the selected container of the active form. Deletes the selected components. Tests the active form. Creates live instances of the form in a new window. You can close that window by pressing the Esc key when the window has the focus. If your form contains more than one top-level component, use the drop-down menu to test another component. Allows you to change the look and feel of the components in the Design view. You can add other look and feels in the Preferences.
Shows diagonals. Simulates evaluating a graphic layout by squinting your eyes. This tests legibility and whether the overall layout is a strong, clear layout. You can change the squint intensity in the Preferences. Refresh the Design view of the active form. Reloads all classes used by the form and recreates the form preview shown in the Design view. You can use this command, if you changed the code of a component used in the form to reload the component classes. But usually this is not necessary because JFormDesigner automatically reloads component classes. Allows you to change the locale of the form in the Design view. "(no locale)" is show if the form is not localized. Use Form > Externalize Strings to start localizing a form.
Refresh Designer
Edit localization settings, resource bundle strings, create new locales or delete locales. Shows the Bindings view. Generates the Java code for the active form. Usually it's not necessary to use this command because when you save a form, the Java code will be also generated. Displays help topics.
- 11 -
3.3
Design View
This view is the central part of JFormDesigner. It displays the opened forms and lets you edit forms.
Stand-alone: At top of the view, tabs are displayed for each open form. Click on a tab to activate a form. To close a form, click the symbol that appears on the right side of a tab if the mouse is over it. An asterisk (*) in front of the form name indicates that the form has been changed. IDE plug-ins: The Design view is integrated into the IDEs, which have its own tabs. On the top and left sides of the view, you can see the column and row headers. These are important controls for grid-based layout managers. Use them to insert, delete or move columns/rows and change column/row properties. In the center is the design area. It displays the form, grids and handles. You can drag and drop components, resize, rename, delete components or in-place-edit labels.
Selecting components
To select a single component, click on it. To select multiple components, hold down the Ctrl (Mac: Command) or Shift key and click on the components. To select the parent of a selected component, hold down the Alt key (Mac: Option key) and click on the selected component. To select components in a rectangular area, select Marquee Selection in the Palette and click-and-drag a rectangular selection area in the Design view. Or click-and-drag on the free area in the Design view. All components that lie partially within the selection rectangle are selected.
The selection in the Design view and in the Structure view is synchronized both ways.
Drag feedback
JFormDesigner provides four types of drag feedback.
- 12 -
The gray figure shows the outline of the dragged components. It always follows the mouse location. The green figure indicates the drop location, the yellow figure indicates a new column/row and red figures indicate occupied areas.
Cursor feedback
JFormDesigner uses various cursors while dragging components: The dragged components will be moved to the new location. Either add a new component to the form or copy existing components. Add multiple components of the same type to the form. It is not possible to drop the component at this location.
Add components
To add components, choose a component from the Palette and drop it to the location where you want to add it. To add multiple instances of a component, hold down the Ctrl key (Mac: Command key) while clicking on the Design view.
To copy components, proceed just as moving components, but hold down the Ctrl key (Mac: Option key) before dropping the components. You can cancel all drag operations using the Esc key.
Resize components
Use the selection handles to resize components. Click on a handle and drag it.
The green feedback figure indicates the new size of the component. The tool tip provides additional information about location, size and differences. Whether a component is resizable or not depends on the used layout manager.
- 13 -
Morph components
The "Morph Bean" command allows you to change the class of existing components without loosing properties, events or layout information. Right-click on a component in the Design or Structure view and select Morph Bean from the popup menu.
Nest in Container
The "Nest in Container" command allows you to nest selected components in a new container (usually a JPanel). Right-click on a component in the Design or Structure view and select Nest in JPanel from the popup menu. The new container gets the same layout manager as the old container and is placed at the same location where the selected components were located. For grid-based layout managers, the new container gets columns and rows and the layout constraints of the selected components are preserved.
Non-visual beans
To add a non-visual bean to a form, select it in the Palette (or use Choose Bean) and drop it into the free area of the Design view. Non-visual beans are shown in the Design view using proxy components.
Red beans
If a bean could not instantiated (class not found, exception in constructor, etc), a red bean will be shown in the designer view as placeholder.
To fix such problems, take a look at the Error Log view and if necessary add required jars to the classpath of your project.
3.3.1
Headers
The column and row headers (for grid-based layout managers) show the structure of the layout. This includes column/row indices, alignment, growing and grouping.
Use them to insert, delete or move columns/rows and change column/row properties. Right-clicking on a column/row displays a popup menu. Double-clicking shows a dialog that allows you to edit the column/row properties.
- 14 -
If a column width or row height is zero, which is the case if a column/row is empty, then JFormDesigner uses a minimum column width and row height. Columns/rows having a minimum size are marked with a light-red background in the column/row header.
Selecting columns/rows
You can select more than one column/row. Hold down the Ctrl key (Mac: Command key) and click on another column/row to add it to the selection. Hold down the Shift key to select the columns/rows between the last selected and the clicked column/row.
Insert column/row
Right-click on the column/row where you want to insert a new one and select Insert Column / Insert Row from the popup menu. The new column/row will be inserted before the right-clicked column/row. To add a column/row after the last one, right-click on the area behind the last column/row. If the layout manager is FormLayout, an additional gap column/row will be added. Hold down the Shift key before selecting the command from the popup menu to avoid this. Besides using the popup menu, you can insert new columns/row when dropping components on column/row gaps or outside of the existing grid. In the first figure, a new row will be inserted between existing rows. In the second figure, a virtual grid is shown below/right to the existing grid and a new row will be added.
Delete columns/rows
Right-click on the column/row that you want delete and select Delete Column / Delete Row from the popup menu. If the layout manager is FormLayout, an existing gap column/row beside the removed column/row will also be removed. Hold down the Shift key before selecting the command from the popup menu to avoid this.
Split columns/rows
Right-click on the column/row that you want split and select Split Column / Split Row from the popup menu. If the layout manager is FormLayout, an additional gap column/row will be added. Hold down the Shift key before selecting the command from the popup menu to avoid this.
- 15 -
Move columns/rows
The headers allow you to drag and drop columns/rows (incl. contained components and gaps). This allows you to swap columns or move rows in seconds. Click on a column or row and drag it to the new location. JFormDesigner updates the column/row specification and the locations of the moved components.
If the layout manager is FormLayout, then existing gap columns/rows are also moved. Hold down the Shift key before dropping a column/row to avoid this.
Resize columns/rows
To change the (minimum) size of a column/row, click near the right edge of a column/row and drag it.
FormLayout supports minimum and constant column/row sizes. Hold down the Ctrl key to change the minimum size. TableLayout supports only constant sizes and GridBagLayout supports only minimum sizes.
Header symbols
Following symbols are used in the headers: Column Header Left aligns components in the column. Right aligns components in the column. Center components in the column. Fill (expand) components into the column. Grow column width. Group column with other columns. All columns in a group will get the same width. Row Header Top aligns components in the row. Bottom aligns components in the row. Center components in the row. Fill (expand) components into the row. Baseline aligns components in the row. Aligns components above baseline in the row. Aligns components below baseline in the row.
- 16 -
Grow row height. Group row with other rows. All rows in a group will get the same height.
3.3.2
In-place-editing
In-place-editing allows you to edit the text of labels and other components directly in the Design view. Simply select a component and start typing. JFormDesigner automatically displays a text field that allows you to edit the text.
You can also use the Space key or double-click on a component to start in-place-editing. Confirm your changes using the Enter key, or cancel editing using the Esc key. In-place-editing is available for all components, which support one of the properties textWithMnemonic, text or title. In-place-editing is also supported for the title of TitledBorder and the tab titles of JTabbedPane.
TitledBorder: double-click on the title of the TitledBorder; or select the component with the TitledBorder and start in-place-editing as usual. JTabbedPane: double-click on the tab title; or single-click on the tab, whose title you want to edit and start in-place-editing as usual.
3.3.3
Keyboard Navigation
Keyboard navigation allows you to change the selection in the designer view using the keyboard. This allows you for example to edit a bunch of labels using in-place-editing without having to use the mouse. You can use the following keys: Key Up Down Left Right Home End Description move the selection up move the selection down move the selection left move the selection right select the first component select the last component
Note: Keyboard navigation is currently limited to one container. You cannot move the selection to another container using the keyboard.
3.3.4
Menu Designer
The menu designer makes it easy to create and modify menu bars and popup menus. It supports in-place-editing menu texts and drag-and-drop menu items.
- 17 -
The component palette provides a category "Menus" that contains all components necessary to create menus.
You can freely drag and drop the various menu components to rearrange them.
- 18 -
Note that JFormDesigner must run on Java 5 (or later) to use the "componentPopupMenu" property. Open the JFormDesigner About dialog and check whether it displays "Java 1.5.x" (or later).
3.3.5
Button Groups
Button groups (javax.swing.ButtonGroup) are used in combination with radio buttons to ensure that only one radio button in a group of radio buttons is selected.
To visualize the grouping, JFormDesigner displays lines connecting the grouped buttons.
Group Buttons
To create a new button group, select the buttons you want to group, right-click on a selected button and select Group Buttons from the popup menu.
You can extend existing button groups by selecting at least one button of the existing group and the buttons that you want to add to that group, then right-click on a selected button and select Group Buttons from the popup menu. Note that the Group Buttons and Ungroup Buttons commands are only available in the context menu if the selection contains only components that are derived from JToggleButton (JRadioButton and JCheckBox).
- 19 -
Ungroup Buttons
To remove a button group, select all buttons of the group, right-click on a selected button and select Ungroup Buttons from the popup menu. To remove a button from a group, right-click on it and select Ungroup Buttons from the popup menu.
ButtonGroup object
Button groups are non-visual beans. They appear at the bottom of the Structure view and in the Design view. JFormDesigner automatically creates and removes those objects. You can rename button group objects.
If a grouped button is selected, you can see the association to the button group in the Properties view.
3.3.6
JTabbedPane
JTabbedPane is a container component that lets the user switch between pages by clicking on a tab. After adding a JTabbedPane to your form, it looks like this one:
To add pages, select an appropriate component (e.g. JPanel) in the palette, move the cursor over the tabs area of the JTabbedPane and click to add it.
- 20 -
You can see only the components of the active tab. Click on a tab to switch to another page. To change a tab title, double-click on a tab to in-place-edit it. You can edit other tab properties (tool tip text, icon, ...) in the Properties view. Select a page component (e.g. JPanel) to see its tab properties.
To change the tab order, select a page component (e.g. JPanel) and drag it over the tabs to a new place. You can also drag and drop page components in the Structure view to change its order.
Use an empty border to separate the page contents from the JTabbedPane border. If you are using JGoodies Forms, it's recommended to use TABBED_DIALOG_BORDER. Otherwise use an EmptyBorder.
3.3.7
Events
Components can provide events to signal when activity occurs (e.g. button pressed or mouse moved). JFormDesigner shows events in the Events category in the Properties view.
- 21 -
The
icon in the popup menu indicates that the listener interface will be implemented (e.g. icon indicates that the listener adapter class will be used (e.g. and are used when the
javax.swing.ChangeListener). The
After selecting an event listener from the popup menu, you can specify the name of the handler method and whether listener methods should be passed to the handler method in following dialog. If you add a PropertyChangeListener, you can also specify a property name (field is not visible in screenshot). Then the listener is added using the method addPropertyChangeListener(String propertyName, PropertyChangeListener listener). The "Go to handler method in Java editor" check box is only available in the IDE plug-ins.
Stand-alone: After saving the form, go to your favorite IDE and implement the body of the generated event handler method. If you use the Runtime Library and the Java code generator is disabled, you must implement the handler method yourself in the target class. See documentation of method FormCreator.setTarget() in the JFormDesigner Loader API for details.
- 22 -
3.4
Palette
The component palette provides quick access to commonly used components ( JavaBeans) available for adding to forms. The components are organized in categories. Click on a category header to expand or collapse a category. You can add a new component to the form in following ways: Select a component in the palette, move the cursor to the Design or Structure view and click where you want to add the component. Select Choose Bean, enter the class name of the component in the Choose Bean dialog, click OK, move the cursor to the Design or Structure view and click where you want to add the component. To add multiple instances of a component, hold down the Ctrl key (Mac: Command key) while clicking on the Design or Structure view. The component palette is fully customizable. Right-click on the palette to add, edit, remove or reorder components and categories. Or use the Palette Manager.
Toolbar commands Palette Manager Opens the Palette Manager dialog to customize the palette.
Palette Manager
This dialog allows you to fully customize the component palette. You can add, edit, remove or reorder components and categories.
- 23 -
Choose Bean
You can use any component that follows the JavaBean specification in JFormDesigner. Select Choose Bean in the palette to open the Choose Bean dialog. Search tab On this tab you can search for classes. Enter the first few characters of the class you want to choose until it appears in the matching classes list. Then select it in the list and click OK. Following pattern kinds are supported: Wildcards: "*" for any string; "?" for any character; terminating "<" or " " (space) prevents implicit trailing "*" Camel case: "JB" for classes containing "J" and "B" as upper-case letters in camel-case notation, e.g. JButton or JideButton; "DaPi" for classes containing "Da" and "Pi" as parts in camel-case notation, e.g. DatePicker The matching classes list displays all classes that match. It is separated into up to three sections: History matches: classes found in the history of last used classes. If the search field is empty, the complete history is displayed. To delete a class from the history, select it and press the Delete key or right-click on it an select Delete from the popup menu. Project matches: classes found in the Classpath specified in the current Project. Palette matches: classes found in the palette.
Filter Menu Options Use Filter Show Interfaces Classes are hidden if they do not match the filter. E.g. if the JavaBean filter is active and the class is not public or does not have a public constructor. Includes interfaces in the list of matching classes.
- 24 -
JARs tab On this tab you can select classes that are marked as JavaBean in the JAR's manifest. The provider of the component JAR can mark some classes as JavaBean in the manifest file. Popular 3rd party component libraries like MiG Calendar or JIDE components use this to make it easier to find the few classes, which can be used in GUI builders, in libraries that contain hundreds of classes.
See also http://download.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#Per-Entry%20Attributes Other options The Is Container check box allows you to specify whether a bean is a container or not. If you select Add to palette category, the component will be added to the palette category specified in the following field. Click the New button to create a new category for your components if necessary. Stand-alone: Use the Classpath button to specify the location of your component classes. Add your JAR files or class folders. IDE plug-ins: The classpath specified in the IDE project is used to locate component classes.
- 25 -
3.5
Structure View
Each component is shown in the tree with an icon, its name and additional information like layout manager class or the text of a label or button. The name must be unique within the form and is used as variable name in the generated Java code. You can edit the name of the selected component in the tree by pressing the F2 key. Right-click on a component to invoke commands from the context menu. The selection in the Structure view and in the Design view is synchronized both ways.
The tree supports multiple selection. Use the Ctrl key (Mac: Command key) to add individual selections. Use the Shift key to add contiguous selections. The tree supports drag and drop to rearrange components. You can also add new components from the palette to the Structure view. Besides the feedback indicator in the structure tree, JFormDesigner also displays a green feedback figure in the Design view to show the new location.
Various overlay icons are used in the tree to indicate additional information: Icon Description The component is bound to a Java class. Each component can have its own (nested) class. See Nested Classes for details. The component has bindings assigned to it. The bindings are shown in Bindings view and in the Bindings category in the Properties view. The component has events assigned to it. The events are shown in the Events category in the Properties view. The component has custom code assigned to it. See Code Generation properties. The variable modifier of the component is set to public. See Code Generation properties. The variable modifier of the component is set to default. The variable modifier of the component is set to protected. The variable modifier of the component is set to private. A property (e.g. JLabel.labelFor) of the component has a reference to a non-existing component. This can happen if you e.g. remove a referenced JTextField. In the above screenshot, the component phoneLabel has a invalid reference.
Toolbar commands Expand All Collapse All Expand all nodes in the structure tree. Collapse all nodes in the structure tree.
- 26 -
3.6
Properties View
The Properties view displays and lets you edit the properties of the selected component(s). Select one or more components in the Design or Structure view to see its properties. If more than one component is selected, only properties that are available in all selected components are shown. The properties table displays the component name, component class, layout manager and constraints properties, bindings, events, client properties, component properties and code generation properties. The list of component properties comes from introspection of the component class (JavaBeans). Properties are organized in categories, which you can expand/collapse by clicking on the category name or on the small plus/minus icons. The number of properties in a category and the number of set properties is displayed near the category name. The category names of component property categories (Properties, Expert Properties, etc) are displayed in blue color. Different font styles are used for the property names. Bold style is used for preferred (often used) properties, plain style for normal properties and italic style for expert properties. Read-only properties are shown using a gray font color. The light gray background indicates unset properties. The shown values are the default values of the component. The white background indicates set properties. Java code will be generated for set properties only. Use Restore Default Value ( ) to unset a property. Use Set Value to null ( the popup menu to set a property explicitly to null. ) from
A small arrow ( ) near the property name indicates that the property is bound.
Use Group by Category ( ) to organize component properties into three predefined categories (normal, expert and read-only) and custom categories (defined in BeanInfo). Group by Defining Type ( ) organizes component properties into defining types (e.g. JTextField, JTextComponent, JComponent, Container, Component). Alphabetical ( ) shows all component properties in one category.
You can either edit a value directly in the property table or use a custom property editor by clicking on the ellipsis button ( ) on the right side. The custom editor pops up in a new dialog. The globe button ( ), which is only available for localized forms and string properties, allows you to choose existing strings from the resource bundle of the form. The type of the editor depends on the data type of the property. JFormDesigner has built-in property editors for all standard data types. For numbers, a spinner editor makes it easier to increase or decrease the value using the arrow buttons or Up and Down keys. Press the Enter key to confirm the change; or the Esc key to cancel it.
- 27 -
Class
Layout Constraints
3.6.1
Each container component that has a layout manager has layout properties. The list of layout properties depends on the used layout manager. Select a container component in the Design or Structure view to see its layout properties in the Properties view.
- 28 -
This screenshot shows layout manager properties (alignment, horizontal and vertical gap) of a container that has a FlowLayout. When you add a container component to a form, following dialog appears and you can choose the layout manager for the new container. You can also set the layout properties in this dialog.
3.6.2
Layout Constraints properties are related to layout managers. Some layout managers (FormLayout, TableLayout, GridBagLayout, ...) use constraints to associate layout information (e.g. grid x/y) to the child components of a container. The list of constraints properties depends on the layout manager of the parent component. Select a component in the Design or Structure view to see its constraints properties in the Properties view.
- 29 -
3.6.3
Client Properties
3.6.4
Component
Property Name Nested Class Name Variable Name Variable Modifiers Use Local Variable Description The name of the generated nested Java class. See Nested Classes for details. The variable name of the component used in the generated Java code. By default, it is equal to the component name. The modifiers of the variable generated for the component. Allowed modifiers: public, default, protected, private, static and transient. Default is private. If true, the variable is declared as local in the initialization method. Otherwise at class level. Default is false.
- 30 -
Property Name Gen. Getter Method Variable Annotations (Java 5) Type Parameters (Java 5) Custom Create
Description If true, generate a public getter method for the component. Default is false. Annotations of component variable (Java 5). Parameters of component type (Java 5). E.g. MyTypedBean<String>. If true, create component in createUIComponents() method. Useful if you want use component factories for or non-default constructors. JFormDesigner generates the createUIComponents() method, but no component instantiation code. It is your responsibility to add code to createUIComponents(). Custom code for creation of the component. Code included before creation of the component. Code included after creation of the component. Code included before initialization of the component. Code included after initialization of the component.
Custom Creation Code Pre-Creation Code Post-Creation Code Pre-Initialization Code Post-Initialization Code
"(form)" properties
Select the "(form)" node in the Structure view to modify special form properties: Property Name Set Component Names Description If true, invokes java.awt.Component.setName() on all components of the form.
Code Generation category Property Name Generate Java Source Code Default Variable Modifiers Default Use Local Variable Default Gen. Getter Method Default Handler Modifiers Member Variable Prefix Use 'this' for member variables I18n Initialization Method I18n 'getBundle' Template I18n 'getString' Template Description If true, generate Java source code for the form. Defaults to "Generate Java source code" option in the Java Code Generator preferences. The default modifiers of the variables generated for components. Allowed modifiers: public, default, protected, private, static and transient. Default is private. If true, the component variables are declared as local in the initialization method. Otherwise at class level. Default is false. If true, generate public getter methods for components. Default is false. The default modifiers used when generating event handler methods. Allowed modifiers: public, default, protected, private, final and static. Default is private. Prefix used for component member variables. E.g. "m_". If enabled, the code generator inserts 'this.' before all member variables. E.g. this. nameLabel.setText("Name:"); If enabled, the code generator puts the code to initialize the localized texts into a method initComponentsI18n(). You can invoke this method from your code to switch the locale of a form at runtime. Template used by code generator for getting a resource bundle. Default is ResourceBundle.getBundle(${bundleName}) Template used by code generator for getting a string from a resource bundle. Default is ${bundle}.getString(${key})
- 31 -
Description The name of a class that contains constants for resource keys. If enabled, the code generator puts the code to create bindings into a method initComponentBindings().
3.6.5
Property Editors
Property editors are used in the Properties view to edit property values.
You can either edit a value directly in the property table or use a custom property editor by clicking on the ellipsis button ( ) on the right side. The custom editor pops up in a new dialog. The type of the editor depends on the data type of the property. JFormDesigner has built-in property editors for all standard data types. Custom JavaBeans can provide their own property editors. Take a look at the API documentation of java.beans.PropertyEditor, java.beans.PropertyDescriptor and java.beans.BeanInfo and the JavaBeans topic for details.
- 32 -
ActionMap (javax.swing)
This (read-only) custom editor allows you to see the actions registered for a component in its action map. The information in the column "Key Stroke" comes from the input map of the component and shows which key strokes are assigned to actions. The JComponent property "actionMap" is read-only. Expand the Read-only Properties category in the Properties view to make it visible.
Border (javax.swing)
You can either select a border from the combo box in the properties table or use the custom editor.
In the custom editor you can edit all border properties. Use the combo box at the top of the dialog to choose a border type. In the mid area of the dialog you can edit the border properties. This area is different for each border type. At the bottom, you can see a preview of the border. Following border types are supported: BevelBorder CompoundBorder DropShadowBorder (SwingX) EmptyBorder EmptyBorder (JGoodies) EtchedBorder LineBorder MatteBorder SoftBevelBorder TitledBorder Swing look and feel custom borders
- 33 -
Color (java.awt)
In the properties table, you can either enter RGB values, color names, system color names or Swing UIManager color names. When using a RGB value, you can also specify the alpha value by adding a fourth number.
The custom editor supports various ways to specify a color. Besides RGB, you can select a color from the AWT, System or Swing palettes.
ComboBoxModel (javax.swing)
This custom editor allows you to specify string values for a combo box.
Cursor (java.awt)
This editor allows you to choose a predefined cursor.
- 34 -
Dimension (java.awt)
Either edit the dimension in the property table or use the custom editor.
Font (java.awt)
You can either use absolute fonts, derived fonts or predefined fonts of the look and feel. Derived fonts are recommended if you just need a bold/italic or a larger/smaller font (e.g. for titles), because derived fonts are computed based on the current look and feel. If your application runs on several look and feels (e.g. several operating systems), derived fonts ensure that the font family stays consistent. In the properties table, you can quickly change the style (bold and italic) and the size of the font.
In the custom editor you can choose one of the tabs to specify either absolute fonts, derived fonts or predefined fonts.
- 35 -
InputMap (javax.swing)
This (read-only) custom editor allows you to see the key strokes registered for a component in its input map. The information in the column "Action" comes from the action map of the component and shows which action classes are assigned to key strokes. The JComponent property "inputMap" is read-only. Expand the Read-only Properties category in the Properties view to make it visible.
- 36 -
Insets (java.awt)
Either edit the insets in the property table or use the custom editor.
KeyStroke (javax.swing)
In the properties table, you can enter a string representation of the keystroke. E.g. "Ctrl+C" or "Ctrl+Shift+S". The custom editor supports two ways to specify a keystroke. Either type any key stroke combination if the focus is in the first field or use the controls below. The KeyStroke editor supports menu shortcut modifier key (Command key on the Mac, Ctrl key otherwise).
ListModel (javax.swing)
This custom editor allows you to specify string values for a list.
- 37 -
Object (java.lang)
This editor allows you to reference any (non-visual) JavaBean as a property value. Often used for JLabel.labelFor.
Paint (java.awt)
This editor allows you to specify a java.awt.Paint object (used by java.awt.Graphics2D). Use the combo box at the top of the dialog to choose a paint type. In the mid area of the dialog you can edit the paint properties. This area is different for each paint type. At the bottom, you can see a preview of the paint. For GradientPaint you can click-and-drag the handles in the preview area to move the points. Following paint types are supported: Color GradientPaint
- 38 -
Point (java.awt)
Either edit the point in the property table or use the custom editor.
Rectangle (java.awt)
Either edit the rectangle in the property table or use the custom editor.
SpinnerModel (javax.swing)
This custom editor allows you to specify a spinner model (used by JSpinner). Use the combo box at the top of the dialog to choose a spinner model type (Number, Date or List). In the mid area of the dialog you can edit the model properties. This area is different for each model type. At the bottom, you can see a test spinner where you can test the spinner model.
- 39 -
String (java.lang)
Either edit the string in the property table or use the custom editor. Switch the "allow new-line" check box on, if you want enter new lines.
String[] (java.lang)
This custom editor allows you to specify string values for a string array.
- 40 -
TableModel (javax.swing)
This custom editor allows you to specify values for a table.
TreeModel (javax.swing)
This custom editor allows you to specify string values for a tree.
- 41 -
3.7
Bindings View
The Bindings view displays and lets you edit all bindings of the form. The bindings and binding groups are shown in the order they will be bound. This view is not visible by default. It appears at the bottom of the main window when you click the Show Bindings View button ( ) in the toolbar.
The icon between the source and the target columns indicate the update strategy used by the binding: Always sync (read-write) Only read from source (read-only) Read once from source (read-once) Toolbar and context menu commands Add Add Group Remove Properties Move Up Move Down Link with Designer Close Create a new binding. Create a new binding group. Remove the selected bindings. Displays the properties of the selected binding in the Binding dialog. Move the selected bindings up. Move the selected bindings down. Links the bindings selection to the active designer. Closes the Bindings view.
- 42 -
3.8
This view appears at the bottom of the main window if an exception is throw by a bean. You can see which bean causes the problem and the stack trace of the exception. This makes it much easier to solve problems when using your own (or 3rd party) beans.
Toolbar commands Copy Log Clear Log Properties Close Copies all log records to the clipboard. Clears the log. Displays the properties of the selected log record in a dialog (see below). Closes the Error Log view.
If you are using 3rd party beans, it is possible that you need to add additional libraries to the classpath. You should be able to identify such a problem on the kind of exception. In this case, add the needed libraries to the JFormDesigner classpath of the current Project, and refresh the Design view.
- 43 -
Localization
Externalize and internalize strings. Edit resource bundle strings. Create new locales. Delete locales. Switch locale used in Design view. In-place-editing strings of current locale. Auto-externalize strings. Choose existing strings. Updates resource keys when renaming components. Copies resource strings when copying components. Removes resource strings when deleting components. Localization preferences. Fully integrated in undo/redo.
The locales combo box in the toolbar allows you to select the locale used in the Design, Structure and Properties views. If you in-place-edit a localized string in the Design view , you change it in the current locale. A small globe in front of property values in the Properties view indicates that the string is localized (stored in a properties file).
- 44 -
- 45 -
The Resource bundle name field is used to locate the properties files within the Source Folders of the current Project. Use the Browse button to choose a resource bundle (.properties file). In the Prefix for generated keys field you can specify a prefix for generated resource bundle keys. The format for generated keys is "<prefix>.<componentName>.<propertyName>". You can change the separator ('.') in the Localization preferences. If the Auto-externalize strings check box is selected, then JFormDesigner automatically puts all new strings into the properties file. E.g. when you add a JLabel to the form and change the "text" and "toolTipText" properties, both strings will be put into the properties file. You can exclude properties from externalization in the Localization preferences.
- 46 -
Delete a locale
To delete an existing locale, either select Form > Delete Locale from the main menu, Delete Locale ( ) from the toobar or click the Delete Locale button in the Localize dialog. Select the locale to delete.
- 47 -
Externalize strings
Externalizing allows you to move strings from a .jfd file to a .properties file. If you want localize existing forms, start here. Select Form > Externalize Strings from the main menu or Externalize Strings ( ) from the toolbar, specify the resource bundle name, the prefix for generated keys and select/deselect the strings to externalize. You can exclude properties from externalization in the Localization preferences.
You can also externalize and internalize properties in the Properties view.
- 48 -
Internalize strings
Internalizing allows you to move strings from a .properties file to a .jfd file. Select Form > Internalize Strings from the main menu or Internalize Strings ( ) from the toolbar, specify the locale to internalize from and select/deselect the strings to internalize. If you internalize all strings, JFormDesigner asks you whether you want to disable localization for the form.
In the Choose Key dialog you can search for keys and/or values. Then select a key in the table and press OK to use its value in the form.
- 49 -
JFormDesigner supports the Beans Binding specification (JSR 295). A binding syncs two properties: the source property with the target property. The source is usually a (non-visual) data model object and the target is usually an UI component (e.g. a JTextField). Initially the value of the source property is copied to the target property. Depending on the "Update strategy", a binding tracks changes on both properties and syncs the properties.
Beans Binding is open source and not part of the standard Java distribution. You must ship an additional library with your application. JFormDesigner includes beansbinding.jar, beansbinding-doc.zip and beansbinding-src.zip in its redist folder. For more documentation and tutorials, visit beansbinding.java.net. The API documentation is also available here: doc.formdev.com/beansbinding/.
The Bindings view gives a good overview of all bindings in the form. The Show Bindings View button makes this view visible. The Bindings property category in the Properties view shows the bindings of the selected component and you can add ( ), edit ( ) and remove ( ) bindings. Small arrows indicate that the property is bound. Binding groups are also shown in the Structure view . The Binding palette category provides useful components.
- 50 -
Add/Edit Bindings
There are several ways to add/edit bindings: Right-click on a component in the Design or Structure view and select Bind from the popup menu. To edit an existing binding, select a bound property from the Bind submenu. Click the Add/Edit Binding button ( / ) in the Bindings property category in Properties view.
Right-click on a component property in the Properties view and select Bind from the popup menu. Use the Add/Properties command in the Bindings view.
Remove Bindings
To remove existing bindings do one of: Click the Remove Binding button ( ) in the Bindings property category in Properties view.
Binding Dialog
This dialog enables you to edit all options of one binding. General tab Field Source Source path Detail path Description The source object. The path (or expression) that identifies the source property. The path (or expression) that determines what is displayed to the user in the target JList.
(only if target is JList.elements)
The target object. The path (or expression) that identifies the target property. Specifies how the properties are kept synchronized. Possible values: "Always sync (read-write)", "Only read from source (read-only)" and "Read once from source (read-once)". Specifies when the source is updated from the target. Possible values: "While typing", "On focus lost" and "On focus lost or Enter key pressed".
(only if target is JTextComponent.text)
Ignore If enabled, do not update properties until the adjusting user finished adjusting. E.g. while a slider is adjusting its value or while the list selection is being updated.
(only if target is JSlider.value, JList.selectedElement(s) or JTable.selectedElement(s))
- 51 -
Advanced tab Field Name Group Converter Description The binding's name. Useful for BindingGroup.getBinding(name). The group this binding belongs to. The Converter that converts the value from source type to target type and vice versa. The Validator that validates the value before passing it from the target back to the source property. Used if the value of the source property is null. Used if the source property is unreadable. Used if the value of the target property is null.
Validator
Bind Bind this binding immediately after immediately creation. Otherwise bind when the group is bound.
Table Binding tab On this tab you can bind List<E> element properties to JTable columns. Each item in the source List<E> represents a row in the JTable. See JTableBinding for details about table binding. This tab is enabled if source is an instance of java.util.List<E>, target an instance of javax.swing.JTable and target property is elements. Field Editable Description Specifies whether the table cells are editable or not.
Columns The column bindings. The Source Path identifies the source property in <E>. The Column Name is shown in the JTable column header. Each column binding may have its own Converter, Validator and Alternative Values.
- 52 -
Path or Expression
To address source or target properties you can either use a path or an expression. Select the Expression Language button ( ) left to the input field to enter an expression. A path (implemented by BeanProperty) uses a dot-separated path syntax. E.g. task.title addresses the title property of an object's task property. This is equivalent to source.getTask().getTitle(). An expression (implemented by ELProperty) uses the Expression Language (EL) also known from JSP and JSF. Besides a dot-separated path syntax to address properties (e.g. "${task.title}") it also supports following operators: Arithmetic: +, -, *, / and div, % and mod Logical: and, &&, or, ||, not, ! Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le Empty: empty Conditional: A ? B : C EL expression examples: EL expression ${task.title} ${firstName} ${lastName} ${mother.age > 65} ${image.width * image.height} ${image.width * image.height * 4} Result The title property of an object's task property. Concatenation of firstName and lastName properties. true if mother is older than 65, false otherwise. Computes the number of pixels of an image. Computes the number of bytes of an 32 bit image.
Following words are reserved for the EL and should not be used as identifiers: and eq true or not ne lt false null div mod gt ge le empty instanceof
Data model
The data model used by Beans Binding (JSR 295) is based on the JavaBeans specification. Getters are necessary to read property values and setters to modify property values. On modifications, property change events should be fired so that beans binding can update the UI components. E.g.:
public class Task { private String title; public String getTitle() { return title; } public void setTitle(String title) { String oldTitle = this.title; this.title = title; changeSupport.firePropertyChange("title", oldTitle, title); } private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); public void addPropertyChangeListener(PropertyChangeListener listener) { changeSupport.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { changeSupport.removePropertyChangeListener(listener); } }
- 53 -
After compiling the form class, you can use this as binding source and task.someProperty as binding source path. Add a setter to the form class, if the whole data model may change. E.g.:
public class TaskViewForm extends JPanel { public void setTask(Task task) { Task oldTask = this.task; this.task = task; firePropertyChange("task", oldTask, task); } }
Examples
For examples that use Beans Binding, take a look at the package com.jformdesigner.examples.beansbinding in the examples.
- 54 -
Projects
Stand-alone edition only. The IDE plug-ins use the source folders and classpath from the IDE projects. Projects allow you to store project specific options in project files. You can create new projects or open existing projects using the menubar or toolbar. When you start JFormDesigner the first time, it creates and opens a default project named DefaultProject.jfdproj in the folder ${user.home}/.jformdesigner, where ${user.home} is your home directory. You can see the value of ${user.home} in the About dialog on the System tab. You can use the default project, but it is recommended to create an own JFormDesigner project in your project root folder. Then you can commit the JFormDesigner project file into a version control system and reuse it on other computers. Paths in the project file are stored relative to the location of the project file. Project files have the extension .jfdproj Pages General Source Folders Classpath Project specific preference pages: FormLayout (JGoodies) null Layout Localization Java Code Generator Templates Layout Managers Localization Binding Code Style Client Properties
General
When creating a new project, you can specify a project name and the location where to store the project file.
- 55 -
Source Folders
On this page, you can specify the locations of your Java source folders. Source folders are the root of packages containing .java files and are used find resource bundles for localization and are also used by the Java code generator to generate package statements.
If the folders list is focused, you can use the Insert key to add folders or the Delete key to delete selected folders.
Classpath
To use your custom components (JavaBeans), JFormDesigner needs to know, from where to load the JavaBean classes. Specify the locations of your custom JavaBeans on this page. You can add JAR files or folders containing .class files.
If the classpath list is focused, you can use the Insert key to add folders/JAR files, the Delete key to delete selected folders/JAR files, Ctrl+Up keys to move selected items up or Ctrl+Down keys to move selected items down.
- 56 -
Preferences
This dialog is used to set user preferences. Stand-alone: Select Window > Preferences from the menu to open this dialog. Eclipse plug-in: The JFormDesigner preferences are fully integrated into the Eclipse preferences dialog. Select Window > Preferences from the menu to open it and then expand the node "JFormDesigner" in the tree. IntelliJ IDEA plug-in: IntelliJ IDEA uses the term "Settings" instead of "Preferences". The JFormDesigner preferences are fully integrated into the IntelliJ IDEA settings dialog. Select File > Settings from the menu to open it and then click the item named "JFormDesigner". JBuilder plug-in: The JFormDesigner preferences are fully integrated into JBuilder preferences dialog. Select Tools > Preferences from the menu to open it. Pages General FormLayout (JGoodies) null Layout Localization Look and Feels Java Code Generator Templates Layout Managers Localization Binding Code Style (Stand-alone only) Client Properties Native Library Paths BeanInfo Search Paths Squint Test Check for Updates Import and export preferences You can use the Import button to import preferences from a file and the Export button to export preferences to a file. This preferences file is compatible with all JFormDesigner editions. On export, you can specify what parts of the preferences you want export. Eclipse plug-in: You can use the menu commands File > Import and File > Export to import and export preferences to/from Eclipse preferences files. IntelliJ IDEA plug-in: You can use the menu commands File > Import Settings and File > Export Settings to import and export settings to/from IntelliJ IDEA preferences files. JBuilder plug-in: Import and export of preferences is not supported. Note: Each IDE uses its own file format for preferences. The only way to transfer preferences between the different JFormDesigner editions is to use JFormDesigner preferences files. Restore defaults Use the Restore Defaults button to restore the values of the active page to its defaults.
- 57 -
General
On this page, you can specify general options.
Option Animate layout changes in Design view Animation speed Buffer Design view in video memory Undo history size
Description If enabled, changes to the layout in the Design view are done animated.
Default On
The speed of the animation. If enabled, parts of the Design view are buffered in the video memory of the graphics card to improve painting speed. The maximum number of steps in the undo history of a form.
default On 1000
- 58 -
FormLayout (JGoodies)
On this page, you can specify FormLayout related options.
Default On
Required JGoodies Forms version for the created forms. JGoodies Forms 1.0.3 and later require Java 1.4 or later. JGoodies Forms 1.0.2 is the last version that supports Java 1.3.
auto-detect
Column/row templates Here you can specify the column and row templates that should be used when for new columns/rows new columns or rows are inserted. Column Column gap The column template used for new columns. The column template used for new gap columns. default label component gap default line gap
The row template used for new rows. The row template used for new gap rows. If the predefined templates does not fit to your needs, you can define your own here. Since JGoodies Forms 1.2 you can add these custom column/row templates to the global LayoutMap using the "LayoutMap Initialization Code" link.
- 59 -
Description The display name is used within JFormDesigner whenever the template is shown in combo boxes or popup menus. The (unique) identifier is stored in form files. Choose a short string. Only letters and digits are allowed. Specifies whether the template should be used for columns, rows or both. Also specifies whether it represents a gap column/row. The default alignment of the components within a column/row. Used if the value of the component constraint properties "h align" or "v align" are set to DEFAULT. The width of a column or height of a row. You can use default, preferred or minimum component size. Or a constant size. It is also possible to specify a minimum and a maximum size. Note that the maximum size does not limit the column/row size if the column/row can grow (see resize behavior). The resize weight of the column/row. Optional Java code used by the Java code generator. Useful if you have factory classes for ColumnSpecs and RowSpecs. Not available for JGoodies Forms 1.2 and later.
- 60 -
null Layout
On this page, you can specify null layout related options.
Description If enabled, snap to the grid specified below when moving or resizing a component in null layout. The horizontal step size of the grid. The vertical step size of the grid.
Default On 5 5
- 61 -
Localization
On this page, you can specify localization related options.
Option Rename resource keys when renaming components Copy localized messages when copying components Delete localized messages when deleting components Delete localized messages when internalizing strings
Description If enabled, auto-rename resource keys when renaming components and the resource key contains the old component name. If enabled, duplicate localized strings in all locales when copying components.
Default On
On
If enabled, auto-delete localized strings, that were used by the deleted components, from all locales. If enabled, auto-delete localized strings, that were internalized, from all locales.
On
On
Delete messages only If enabled, messages will be auto-deleted only if their key prefix is equal to the if key prefix is equal to key prefix of the form. form's key prefix Insert new messages Specifies where new messages will be inserted into properties files. "next to similar keys" inserts new messages next to other similar keys so that messages that belong together are automatically at the same location in the properties file. "at the end of the properties file" always appends new messages to the end of the properties file. Separator used when generating a resource key.
On
- 62 -
Description Template used when creating new properties files. Specify properties that should be excluded from externalization. Useful when using auto-externalization to ensure that some string property values stay in the Java code. If the list is focused, you can use the Insert key to add a property or the Delete key to delete selected properties.
Default
If the look and feels list is focused, you can use the Insert key to add a look and feel or the Delete key to delete selected look and feels.
- 63 -
Description Full path name of the jar file that contains the look and feel classes. Use the Browse button to select a jar. Name of the look and feel used in the look and feel combo box in the Toolbar. Class name of the look and feel class (derived from javax.swing.LookAndFeel). License code for the commercial Alloy Look and Feel.
Option
Description
Default
Generate Java source If enabled, JFormDesigner generates Java source code when you save a On code form. Source compatibility Specifies the compatibility of the generated source code. Besides generating Java 1.x compatible source code, JFormDesigner can also use Java 5 (or later) features in the generated source code (e.g. auto-boxing, @Override, etc). Stand-alone: use JRE version IDE plug-ins: use project setting
If enabled, the code generator adds explicit import statements (without '*') Off for used classes. If enabled, the code generator puts the initialization code for each container into a block (enclosed in curly braces). If enabled, the code generator puts a comment line above the initialization code for each component. On On
- 64 -
Option Set component names Use Eclipse code formatter Eclipse non-nls tags (//$NON-NLS-n$) NetBeans no-i18n tags (//NOI18N) Use 'this' for member variables Member variables prefix Class modifiers Nested class modifiers
Description If enabled, the code generator inserts java.awt.Component.setName() statements for all components of the form. If enabled, the Eclipse code formatter is used to format the generated code. (Eclipse plug-in only) If enabled, the code generator appends non-nls comments to lines containing strings. These comments are used by the Eclipse IDE to denote strings that should not be externalized. If enabled, the code generator appends non-nls comments to lines containing strings. These comments are used by the NetBeans IDE to denote strings that should not be externalized. If enabled, the code generator inserts 'this.' before all member variables. E.g. this.nameLabel.setText("Name:"); Prefix used for component member variables. E.g. "m_". Class modifiers used when generating a new class. Allowed modifiers: public, default, abstract and final. Class modifiers used when generating a new nested class. Allowed modifiers: public, default, protected, private, abstract, final and static.
Default Off
Off Off
Off
Off
public private
You can set additional options per form in the "(form)" properties.
New: Create a new template for a specific superclass. Edit: Edit the superclass of the selected user-defined template. Remove: Remove the selected template. Only allowed for user-defined templates.
- 65 -
Reset: Reset the selected predefined template to the default. Insert Variable: Insert a variable at the current cursor location into the selected template.
Option Use PanelBuilder in generated code Use empty GridBagConstraints constructor GroupLayout Generation Style
Description If enabled, the PanelBuilder class of JGoodies Forms is used for FormLayout. If enabled, the empty GridBagConstraints constructor is used in the generated code, which is necessary for Java 1.0 and 1.1 compatibility. Since Java 1.2, GridBagConstraints has a constructor with parameters, which is used by default. Specifies whether class javax.swing.GroupLayout is used, which is part of Java 6 and later. Or whether org.jdesktop.layout.GroupLayout from the Open Source Swing Layout library swing-layout.jar is used, which is also available for Java 1.4 and 5. Package name used by the Java code generator for TableLayout. Change this only if you have a copy of the original TableLayout in another package.
use source compatibility (see Java Code Generator preferences page) info.clearthought.layout
TableLayout package
- 66 -
Description If enabled, the code generator puts the code to initialize the localized texts into a method initComponentsI18n(). You can invoke this method from your code to switch the locale of a form at runtime. You can set this options also per form in the "(form)" properties. Template used by code generator for getting a resource bundle. Template used by code generator for getting a string from a resource bundle.
Default Off
- 67 -
Option
Description
Default Off
Generate If enabled, the code generator puts the code to create bindings into a method initComponentBindings() initComponentBindings(). You can set this options also per form in the "(form)" method properties.
- 68 -
Option Indent size Tab size Use tab character Line separator Encoding
Description The number of spaces used for one indentation level. The number of spaces that represents one tabulation. Specifies whether the tab character (\t) is used for indentation or only space characters. The line separator used for newly created .java and .properies files. The character encoding used for reading and writing Java files.
Client Properties
On this page, you can can define client properties, which can be set in the Properties view.
- 69 -
If the client properties list is focused, you can use the Insert key to add a client property or the Delete key to delete selected client properties.
Description The key that identifies the client property. The component class(es) to which the client property belongs. E.g. if set to javax.swing.JButton, then the client property is shown in the Properties view for buttons and for subclasses of JButton. To specify multiple classes, separate them with commas. If not specified, the client property is shown for all JComponent components. The type of the client property value. You can select one of the common types (String, Boolean, Integer, etc) from the combo box or enter the class name of a custom type. If the value type is java.lang.String, then you can specify predefined values for the client property. When editing the client property in the Properties view, a combo box that contains these values is shown. The combo box is editable by default. Select the "Allow only predefined values" check box to make the combo box not-editable. Optional class name of a property editor that should be used when editing the client property in the Properties view.
- 70 -
Option
Description
Classpath for JAR files or folders containing .class files, which are using native libraries. They must be JavaBeans, which use specified here to ensure that the native libraries are loaded from a special class loader only native libraries once. Native Library Path Folders used to search for native libraries.
- 71 -
Description Package names that will be used for finding BeanInfo classes. Only necessary if the BeanInfo class is not in the same package as the component class to which it belongs. See java.beans.Introspector and Introspector.setBeanInfoSearchPath() for details.
Property editor search Package names that will be used for finding property editors. Only necessary if the property path editor is not in the same package as the property type to which it belongs. See java.beans.PropertyEditorManager and PropertyEditorManager.setEditorSearchPath() for details.
- 72 -
Squint Test
This page allows you to specify the squint level for the squint test (menu View > Squint Test).
- 73 -
IDE Integrations
JFormDesigner is available as stand-alone application and as plug-ins for various IDEs. The IDE plug-ins completely integrate JFormDesigner into the IDEs. Following IDE plug-ins are available: Eclipse plug-in IntelliJ IDEA plug-in JBuilder plug-in
Other IDEs
If there is no JFormDesigner plug-in for your favorite IDE, you can use the stand-alone edition of JFormDesigner side by side with your IDE. IDE plug-ins for NetBeans and JDeveloper are already under development.
- 74 -
8.1
Eclipse plug-in
This plug-in integrates JFormDesigner into Eclipse and other Eclipse based IDEs.
Benefits
Using this plug-in has following benefits compared to JFormDesigner stand-alone edition: Fully integrated as editor for JFormDesigner .jfd files. Create and design forms within Eclipse. No need to switch between applications. Uses the source folders and classpath of the current Eclipse project. No need to specify them twice. The Java code generator updates the .java file in-memory on each change in the designer. You can design forms and edit its source code without the need to save them (as necessary when using JFormDesigner stand-alone edition). Folding of generated GUI code in Java editor. Go to event handler method in Java editor. Two-way synchronization of localized strings in designer and in properties file editors. Changing localized strings in the designer immediately updates the .properties file in-memory and changing the .properties file updates the designer. Copy needed libraries (JGoodies Forms, TableLayout, etc) to the project and add them to the classpath of the current Eclipse project. Optionally include source code and javadoc. Integrated with Eclipse's Version Control Systems. Integrated into refactoring: Copy, rename, move or delete .jfd files when coping, renaming, moving or deleting .java files.
User interface
The screenshot below shows the Eclipse main window editing a JFormDesigner form. JFormDesigner adds the menu Form to the main menu, which is only visible if a JFormDesigner form editor is active.
A JFormDesigner editor consists of: Toolbar: Located at top of the editor area. Palette: Located at the left side.
- 75 -
Design View: Located at the center. Structure View: Located in Eclipse's Outline view. Properties View: Located in Eclipse's Properties view. Bindings View: Located below the Design view. This view is not visible by default. Click the Show Bindings View button ( ) in the toolbar to make is visible. Error Log View: Automatically opens on errors in a view at the bottom.
You can also create new forms in Eclipse's Package Explorer view. First select the destination package or folder, then invoke Eclipse's New command and select Other, which opens Eclipse's New dialog. Then choose JFormDesigner Form from the list of wizards and click Next to proceed.
If JFormDesigner Form is in the New sub menu, you can choose it directly without the need to open Eclipse's New dialog.
In the New JFormDesigner Form dialog, enter the form name (which is also used as class name), choose a superclass, a layout manager and set localization options.
- 76 -
Code folding
To move the generated code out of the way, JFormDesigner folds it in the Java editor.
When converting an IntelliJ IDEA form, JFormDesigner inserts its own generated GUI code into the existing Java class and removes IntelliJ IDEA's GUI code.
- 77 -
Preferences
The JFormDesigner preferences are fully integrated into the Eclipse preferences dialog. Select Window > Preferences from the menu to open it and then expand the node "JFormDesigner" in the tree. See Preferences for details. You can also set project specific settings in the Eclipse project dialog. Select Project > Properties from the menu to open it and then expand the node "JFormDesigner" in the tree. See Preferences for details.
Keyboard shortcuts
You can assign shortcut keys to some JFormDesigner commands in Eclipse's keys preferences. Select Window > Preferences > General > Keys to open it. Search for "JFormDesigner" to find JFormDesigner commands.
- 78 -
8.2
This plug-in integrates JFormDesigner into Jetbrains IntelliJ IDEA (Community and Ultimate Editions).
Benefits
Using this plug-in has following benefits compared to JFormDesigner stand-alone edition: Fully integrated as editor for JFormDesigner .jfd files. Create and design forms within IntelliJ IDEA. No need to switch between applications. Uses the source folders and classpath of the current IntelliJ IDEA project/module. No need to specify them twice. The Java code generator updates the .java file in-memory on each change in the designer. You can design forms and edit its source code without the need to save them (as necessary when using JFormDesigner stand-alone edition). Folding of generated GUI code in Java editor. Go to event handler method in Java editor. Two-way synchronization of localized strings in designer and in properties file editors. Changing localized strings in the designer immediately updates the .properties file in-memory and changing the .properties file updates the designer. Copy needed libraries (JGoodies Forms, TableLayout, etc) to the project and add them to the classpath of the current IntelliJ IDEA project/module. Optionally include source code and javadoc. Assign shortcut keys to most JFormDesigner commands in IntelliJ IDEA's keymap settings. Integrated with IntelliJ IDEA's Version Control Systems.
User interface
The screenshot below shows the IntelliJ IDEA main window editing a JFormDesigner form.
A JFormDesigner editor consists of: Toolbar: Located at top of the editor area. Palette: Located at the left side. Design View: Located at the center.
- 79 -
Structure View: Located at the upper right. You can hide this view in the editor and show it instead in IntelliJ IDEA's Structure tool window by unselecting Show Structure in Editor ( Properties View: Located at the lower right. Bindings View: Located below the Design view. This view is not visible by default. Click the Show Bindings View button ( ) in the toolbar to make is visible. Error Log View: Automatically opens on errors in a tool window at the bottom. This view is not visible in the above screenshot. ).
In the New JFormDesigner Form dialog, enter the form name (which is also used as class name), choose a superclass, a layout manager and set localization options.
- 80 -
Code folding
To move the generated code out of the way, JFormDesigner folds it in the Java editor.
When converting an IntelliJ IDEA form, JFormDesigner inserts its own generated GUI code into the existing Java class and removes IntelliJ IDEA's GUI code.
Settings
JFormDesigner uses the term "Preferences" instead of IntelliJ IDEA's "Settings". The JFormDesigner preferences are fully integrated into the IntelliJ IDEA settings dialog. Select File > Settings from the menu to open it and then click the item named "JFormDesigner" in the "IDE Settings" area. To set project specific settings, select the item named "JFormDesigner (Project)" in the "Project Settings" area. See Preferences for details.
Keyboard shortcuts
You can assign shortcut keys to most JFormDesigner commands in IntelliJ IDEA's keymap settings. Select File > Settings > Keymap to open it. In the actions tree expand All Actions > Plug-ins > JFormDesigner.
- 81 -
8.3
JBuilder plug-in
This plug-in integrates JFormDesigner into JBuilder 2006. For JBuilder 2007 (or later) use the Eclipse plug-in. For JBuilder 2005 use JFormDesigner 4.
Benefits
Using this plug-in has following benefits compared to JFormDesigner stand-alone edition: Fully integrated as editor for JFormDesigner .jfd files. Create and design forms within JBuilder. No need to switch between applications. Uses the source folders and classpath of the current JBuilder project. No need to specify them twice. The Java code generator updates the .java file in-memory on each change in the designer. You can design forms and edit its source code without the need to save them (as necessary when using JFormDesigner stand-alone edition). Folding of generated GUI code in Java editor. Go to event handler method in Java editor. Two-way synchronization of localized strings in designer and in properties file editors. Changing localized strings in the designer immediately updates the .properties file in-memory and changing the .properties file updates the designer. Copy needed libraries (JGoodies Forms, TableLayout, etc) to the project and add them to the classpath of the current JBuilder project. Optionally include source code and javadoc. Convert JBuilder forms (jbInit() methods) to JFormDesigner .jfd files.
User interface
The screenshot below shows the JBuilder main window editing a JFormDesigner form.
A JFormDesigner editor consists of: Toolbar: Located at top of the editor area. Palette: Located at the left side. Design View: Located at the center.
- 82 -
Structure View: Located at the lower left. Properties View: Located at the right side. Bindings View: Located below the Design view. This view is not visible by default. Click the Show Bindings View button ( ) in the toolbar to make is visible. Error Log View: Automatically opens on errors in a tool window at the bottom. This view is not visible in the above screenshot.
In the New JFormDesigner Form dialog, enter the form name (which is also used as class name), choose a superclass, a layout manager and set localization options.
- 83 -
Code folding
To move the generated code out of the way, JFormDesigner folds it in the Java editor.
Note: JFormDesigner inserts its own generated GUI code into the existing Java class, but does not remove JBuilder's GUI code. You have to remove JBuilder's component variables and initialization code yourself.
Preferences
The JFormDesigner preferences are fully integrated into the JBuilder preferences dialog. Select Tools > Preferences from the menu to open it. See Preferences for details.
Unsupported features
Following features from other editions are not supported by the JBuilder plug-in: Convert NetBeans, IntelliJ IDEA and Abeille forms to JFormDesigner forms. Use look and feels in Design view. Import and export of preferences.
- 84 -
Layout Managers
Layout managers are an essential part of Swing forms. They lay out components within a container. JFormDesigner provides support for following layout managers: BorderLayout BoxLayout CardLayout FlowLayout FormLayout (JGoodies) GridBagLayout GridLayout GroupLayout (Free Design) HorizontalLayout (SwingX) IntelliJ IDEA GridLayout null Layout TableLayout VerticalLayout (SwingX)
- 85 -
- 86 -
9.1
BorderLayout
The border layout manager places components in up to five areas: center, north, south, east and west. Each area can contain only one component.
(absolute positioning)
The components are laid out according to their preferred sizes. The north and south components may be stretched horizontally. The east and west components may be stretched vertically. The center component may be stretched horizontally and vertically to fill any space left over. In addition to absolute positioning, BorderLayout supports relative positioning, which swaps west and east components if the component orientation of the container is set to right-to-left. To use relative positioning, first add a component to one of the four side areas and then change the layout constraints property of that component to PAGE_START, PAGE_END, LINE_START or LINE_END. BorderLayout is part of the standard Java distribution.
- 87 -
9.2
BoxLayout
The box layout manager places components either vertically or horizontally. The components will not wrap as in FlowLayout.
This layout manager is used rarely. Take a look at the BoxLayout API documentation for more details about it. BoxLayout is part of the standard Java distribution.
- 88 -
9.3
CardLayout
The card layout manager treats each component in the container as a card. Only one card is visible at a time. The container acts as a stack of cards. The first component added to a card layout is the visible component when the container is first displayed. CardLayout is part of the standard Java distribution.
- 89 -
9.4
FlowLayout
The flow layout manager arranges components in a row from left to right, starting a new row if no more components fit into a row. Flow layouts are typically used to arrange buttons in a panel.
The alignment of the layout. Possible values: LEFT, RIGHT, CENTER, LEADING CENTER and TRAILING. The horizontal gap between components and between the component and the border of the container. The vertical gap between components and between the component and the border of the container. Specifies whether components are vertically aligned along their baseline. Components that do not have a baseline are centered. 5 5 false
- 90 -
9.5
FormLayout (JGoodies)
FormLayout is a powerful, flexible and precise general purpose layout manager. It places components in a grid of columns and rows, allowing specified components to span multiple columns or rows. Not all columns/rows necessarily have the same width/height.
Unlike other grid-based layout managers, FormLayout uses 1-based column/row indices. And it uses "real" columns/rows as gaps. Therefore the unusual column/row numbers in the above screenshot. Using gap columns/rows has the advantage that you can give gaps different sizes. Use the column and row headers to insert or delete columns/rows and change column/row properties. JFormDesigner automatically adds/removes gap columns if you add/remove a column/row. Compared to other layout managers, FormLayout provides following outstanding features: Default alignment of components in a column/row. Specification of minimum and maximum column width or row height. Supports different units: Dialog units, Pixel, Point, Millimeter, Centimeter and Inch. Especially Dialog units are very useful to create layouts that scale with the screen resolution. Column/row templates. Column/row grouping. FormLayout is open source and not part of the standard Java distribution. You must ship an additional library with your application. JFormDesigner includes forms.jar, forms-javadoc.zip and forms-src.zip in its redist folder. For more documentation and tutorials, visit www.jgoodies.com or forms.java.net. The API documentation is also available here: doc.formdev.com/jgoodies-forms/. IDE plug-ins: If you use FormLayout the first time, the JFormDesigner IDE plug-in ask you whether it should copy the required library (and its source code and documentation) to the IDE project and add it to the classpath of the IDE project.
- 91 -
Column/row properties
Each column and row has its own properties. Use the column and row headers to change column/row properties. Field Description
Column/Row The index of the column/row. Use the arrow buttons (or Alt+Left, Alt+Right, Alt+Up, Alt+Down keys) to edit the properties of the previous or next column/row. Template FormLayout provides several predefined templates for columns and rows. Here you can choose one.
Specification The column/row specification. This is a string representation of the options below. Default alignment The default alignment of the components within a column/row. Used if the value of the component constraint properties "h align" or "v align" are set to DEFAULT. The width of a column or height of a row. You can use default, preferred or minimum component size. Or a constant size. It is also possible to specify a minimum and a maximum size. Note that the maximum size does not limit the column/row size if the column/row can grow (see resize behavior). The resize weight of the column/row. See column/row grouping for details.
Size
Tip: The column/row context menu allows you to alter many of these options for multi-selections.
Tip: The component context menu allows you to alter the alignment for multi-selections.
- 92 -
9.5.1
Column/Row Templates
FormLayout provides several predefined templates for columns and rows. You can also define custom column/row templates in the Preferences dialog.
Column templates
Name default Description Determines the column width by computing the maximum of all column component preferred widths. If there is not enough space in the container, the column can shrink to the minimum width. Determines the column width by computing the maximum of all column component preferred widths. Determines the column width by computing the maximum of all column component minimum widths. A logical horizontal gap between two related components. For example the OK and Cancel buttons are considered related. A logical horizontal gap between two unrelated components. A logical horizontal gap between a label and an associated component. Has an initial width of 0 pixels and grows. Useful to describe glue columns that fill the space between other columns. A logical horizontal column for a fixed size button. A logical horizontal column for a growing button. Gap no
preferred minimum related gap unrelated gap label component gap glue button growing button
Row templates
Name default Description Determines the row height by computing the maximum of all row component preferred heights. If there is not enough space in the container, the row can shrink to the minimum height. Determines the row height by computing the maximum of all row component preferred heights. Determines the row height by computing the maximum of all row component minimum heights. A logical vertical gap between two related components. A logical vertical gap between two unrelated components. A logical vertical narrow gap between two rows. Useful if the vertical space is scarce or if an individual vertical gap shall be smaller than the default line gap. A logical vertical default gap between two rows. A little bit larger than the narrow line gap. A logical vertical default gap between two paragraphs in the layout grid. This gap is larger than the default line gap. Has an initial height of 0 pixels and grows. Useful to describe glue rows that fill the space between other rows. Gap no
preferred minimum related gap unrelated gap narrow line gap line gap paragraph gap glue
- 93 -
9.5.2
Column/Row Groups
Column and row groups are used to specify that a set of columns or rows will get the same width or height. This is an essential feature for symmetric, and more generally, balanced design.
In the above example, columns [1 and 5] and columns [3 and 7] have the same width. To visualize the grouping, JFormDesigner displays lines connecting the grouped columns/rows near to the column and row headers.
Group columns/rows
To create a new group, select the columns/rows you want to group in the header, right-click on a selected column/row in the header and select Group from the popup menu.
Note that selected gap columns/rows will be ignored when grouping. You can extend existing groups by selecting at least one column/row of the existing group and the columns/rows that you want to add to that group, then right-click on a selected column/row and select Group from the popup menu.
- 94 -
Ungroup columns/lines
To remove a group, select all columns/rows of the group, right-click on a selected column/row and select Ungroup from the popup menu. To remove a single column/row from a group, right-click on it and select Ungroup from the popup menu.
Group IDs
A unique group ID identifies each group. When using the header context menu to group/ungroup, you don't have to care about those IDs. JFormDesigner manages the group IDs automatically. However it is possible to edit the group ID in the Column/row properties dialog.
- 95 -
9.6
GridBagLayout
The grid bag layout manager places components in a grid of columns and rows, allowing specified components to span multiple columns or rows. Not all columns/rows necessarily have the same width/height. Essentially, GridBagLayout places components in rectangles (cells) in a grid, and then uses the components' preferred sizes to determine how big the cells should be.
Use the column and row headers to insert or delete columns/rows and change column/row properties. GridBagLayout is part of the standard Java distribution.
Extensions
JFormDesigner extends the original GridBagLayout with following features: Horizontal and vertical gaps Simply specify the gap size and JFormDesigner automatically computes the GridBagConstraints.insets for all components. This makes designing a form with consistent gaps using GridBagLayout much easier. No longer wrestling with GridBagConstraints.insets. With gaps: Without gaps:
Left/top layout alignment The pure GridBagLayout centers the layout within the container if there is enough space. JFormDesigner easily allows you to fix this problem by switching on two options: align left and align top. With layout alignment: Without layout alignment:
Default component alignment Allows you to specify a default alignment for components within columns/rows. This is very useful for columns with right aligned labels because you specify the alignment only once for the column and all added labels will automatically aligned to the right.
- 96 -
These four properties are JFormDesigner extensions to the original GridBagLayout. However, no additional library is required.
Column/row properties
Each column and row has its own properties. Use the column and row headers to change column/row properties.
Description The index of the column/row. Use the arrow buttons (or Alt+Left, Alt+Right, Alt+Up, Alt+Down keys) to edit the properties of the previous or next column/row. The default alignment of the components within a column/row. Used if the value of the constraints properties "h align" or "v align" is DEFAULT. The minimum width of a column or height of a row. The resize weight of the column/row.
Tip: The column/row context menu allows you to alter many of these options for multi-selections.
weight x
0.0
- 97 -
Description Specifies how to distribute extra vertical space. Specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area. Specifies the internal padding of the component, how much space to add to the minimum width of the component. Specifies the internal padding, that is, how much space to add to the minimum height of the component.
In contrast to the GridBagConstraints API, which uses anchor and fill to specify the alignment and resize behavior of a component, JFormDesigner uses the usual h/v align notation. Tip: The component context menu allows you to alter the alignment for multi-selections.
- 98 -
9.7
GridLayout
The grid layout manager places components in a grid of cells. Each component takes all the available space within its cell, and each cell is exactly the same size.
This layout manager is used rarely. GridLayout is part of the standard Java distribution.
- 99 -
9.8
The goal of the group layout manager is to make it easy to create professional cross platform layouts. It is designed for GUI builders, such as JFormDesigner, to use the "Free Design" paradigm. You can lay out your forms by simply placing components where you want them. Visual guidelines suggest optimal spacing, alignment and resizing of components.
GroupLayout has been developed by the NetBeans team and is also used by the NetBeans GUI Builder (formerly Project Matisse). They provide a comprehensive tutorial on designing GUIs using GroupLayout, which is also suitable for JFormDesigner: http://www.netbeans.org/kb/60/java/quickstart-gui.html GroupLayout is part of the standard Java distribution since Java 6. If you need to run your application also on Java 5 or 1.4, you can use the open-source Swing Layout Extension library, which is compatible to the Java 6 GroupLayout, but uses different package names. Change the option "GroupLayout Generation Style" in the Layout Managers (Java Code Generator) preferences if necessary. The API documentation is available here: doc.formdev.com/grouplayout/. IDE plug-ins: If you use GroupLayout from the Swing Layout Extension library the first time, the JFormDesigner IDE plug-in ask you whether it should copy the required library (and its source code and documentation) to the IDE project and add it to the classpath of the IDE project.
Alignment guidelines
Alignment guidelines appear only when adding or moving components. They indicate the preferred positions to which components snap when releasing the mouse button. Insets are the preferred spacings between components and their container.
- 100 -
Baseline alignment is the preferred relationship between adjacent components that display text.
Edge alignments (top, bottom, left and right) are possible relationships between adjacent components.
Indentation alignment is a special alignment relationship in which one component is located below another and offset slightly to the right.
Anchoring indicators
Anchoring indicators appear when components have snapped into position. They illustrate the alignment and relationship among components.
Anchors connecting components to their container or to adjacent components are represented by small semi-circular indicators with dashed lines.
- 101 -
Commands
The designer context menu provides following GroupLayout specific commands: Command Align in column/row Description Aligns the selected components left/right/top/bottom/center in column/row.
Align
Anchor
Changes the anchoring of the selected components. A component is usually horizontally anchored left/right and vertically anchored top/bottom. Anchoring connects a component to a container edge or a neighborhood component edge. Makes the selected components resize horizontally at runtime if the container size changes. Makes the selected components resize vertically at runtime if the container size changes. Makes the selected components all the same width. If one of the selected components is already in a group of "Same Width" components, the other components are added to the existing group. To remove components from a group, select them and then execute this command. Grouped components are marked with a small indicator.
Makes the selected components all the same height. See "Save Width" command for more details. Makes the selected components have its default size. Changes the empty space around the selected component. Duplicates the selected components and places the new components below the original components. Use Ctrl+Left, Ctrl+Right, Ctrl+Up or Ctrl+Down keys to place the duplicated components left, right, above or below the original components.
Specifies whether component visibility is considered when positioning and sizing true components. If true, non-visible components are not treated as part of the layout. If false, components are positioned and sized regardless of visibility.
- 102 -
Property Name horizontal resizable vertical resizable top space left space bottom space right space top space resizable left space resizable bottom space resizable right space resizable
Description Specifies whether the component is horizontal resizable. Specifies whether the component is vertical resizable. Specifies the top empty space. Specifies the left empty space. Specifies the bottom empty space. Specifies the right empty space. Specifies whether the top empty space is vertical resizable. Specifies whether the left empty space is horizontal resizable. Specifies whether the bottom empty space is vertical resizable. Specifies whether the right empty space is horizontal resizable.
- 103 -
9.9
HorizontalLayout (SwingX)
The horizontal layout manager places components horizontally. The components are stretched vertically to the height of the container. The components will not wrap as in FlowLayout.
HorizontalLayout is part of the SwingX open source project and not part of the standard Java distribution. You must ship an additional library with your application. The JFormDesigner distribution does not include the SwingX library. For downloads, documentation and tutorials, visit swingx.java.net (or www.swinglabs.org).
- 104 -
9.10
The IntelliJ IDEA grid layout manager places components in a grid of columns and rows, allowing specified components to span multiple columns or rows. Not all columns/rows necessarily have the same width/height. Note: The IntelliJ IDEA grid layout manager is supported to make it easier to migrate forms, which were created with IntelliJ IDEA's GUI builder. If you never used it, it is recommended to use one of the other grid-based layout managers.
Use the column and row headers to insert or delete columns/rows and change column/row properties. Use horizontal and vertical spacers, which are available in the Palette, to define space between components. IntelliJ IDEA GridLayout is open source and not part of the standard Java distribution. You must ship an additional library with your application. JFormDesigner includes intellij_forms_rt.jar and intellij_forms_rt_src.zip in its redist folder. For more documentation and tutorials, visit www.jetbrains.com/idea/. IDE plug-ins: If you use IntelliJ IDEA GridLayout the first time, the JFormDesigner IDE plug-in ask you whether it should copy the required library (and its source code) to the IDE project and add it to the classpath of the IDE project.
same size horizontally If true, all columns get the same width. same size vertically margin If true, all rows get the same height. Size of the margin between the containers border and its contents.
- 105 -
Property Name grid height fill anchor indent align grid with parent horizontal size policy
Description Specifies the component's vertical grid extend (number of rows). Specifies how the component fills its cell. Possible values: None, Horizontal, Vertical and Both. Specifies how the component is aligned within its cell. Possible values: Center, North, North East, East, South East, South, South West, West and North West. The indent of the component within its cell. In pixel multiplied by 10. If true, align the grid of nested containers, which use IntelliJ IDEA GridLayout, with the grid of this container. Specifies how the component affects horizontal resizing behavior. Possible values: Fixed, Can Shrink, Can Grow, Want Grow and combinations. Specifies how the component affects vertical resizing behavior. Possible values: Fixed, Can Shrink, Can Grow, Want Grow and combinations. The minimum size of the component. The preferred size of the component. The maximum size of the component.
Default 1 None Center 0 false Can Shrink and Can Grow Can Shrink and Can Grow -1, -1 -1, -1 -1, -1
- 106 -
9.11
null Layout
null layout is not a real layout manager. It means that no layout manager is assigned and the components can be put at specific x,y coordinates.
It is useful for making quick prototypes. But it is not recommended for production because it is not portable. The fixed locations an sizes do not change with the environment (e.g. different fonts on various platforms).
Preferred sizes
JFormDesigner supports preferred sizes of child components. This solves one common problem of null layout: the component sizes change with the environment (e.g. different fonts on various platforms). Unlike other GUI designers, no additional library is required.
Grid
To make it easier to align components, the component edges snap to an invisible grid when moving or resizing components. You can specify the grid step size in the Preferences dialog. To temporary disable grid snapping, hold down the Shift key while moving or resizing components.
Keyboard
You can move selected components with Ctrl+ArrowKey and change size with Shift+ArrowKey.
Aligning components
The align commands help you to align a set of components or make them same width or height.
The dark blue handles in the above screenshot indicate the first selected component. Command Align Left Description Line up the left edges of the selected components with the left edge of the first selected component.
- 107 -
Command Align Center Align Right Align Top Align Middle Align Bottom Same Width Same Height Make Horizontal Space Equal Make Vertical Space Equal
Description Horizontally line up the centers of the selected components with the center of the first selected component. Line up the right edges of the selected components with the right edge of the first selected component. Line up the top edges of the selected components with the top edge of the first selected component. Vertically line up the centers of the selected components with the center of the first selected component. Line up the bottom edges of the selected components with the bottom edge of the first selected component. Make the selected components all the same width as the first selected component. Make the selected components all the same height as the first selected component. Makes the horizontal space between 3 or more selected components equal. The leftmost and rightmost components stay unchanged. The other components are horizontally distributed between the leftmost and rightmost components. Makes the vertical space between 3 or more selected components equal. The topmost and bottommost components stay unchanged. The other components are vertically distributed between the topmost and bottommost components.
- 108 -
9.12
TableLayout
The table layout manager places components in a grid of columns and rows, allowing specified components to span multiple columns or rows. Not all columns/rows necessarily have the same width/height. A column/row can be given an absolute size in pixels, a percentage of the available space, or it can grow and shrink to fill the remaining space after other columns/rows have been resized.
Use the column and row headers to insert or delete columns/rows and change column/row properties. TableLayout is open source and not part of the standard Java distribution. You must ship an additional library with your application. JFormDesigner includes TableLayout.jar, TableLayout-javadoc.jar and TableLayout-src.zip in its redist folder. For more documentation and tutorials, visit tablelayout.java.net. The API documentation is also available here: doc.formdev.com/tablelayout/. IDE plug-ins: If you use TableLayout the first time, the JFormDesigner IDE plug-in ask you whether it should copy the required library (and its source code and documentation) to the IDE project and add it to the classpath of the IDE project.
Extensions
JFormDesigner extends the original TableLayout with following features: Default component alignment Allows you to specify a default alignment for components within columns/rows. This is very useful for columns with right aligned labels because you specify the alignment only once for the column and all added labels will automatically aligned to the right.
- 109 -
Column/row properties
Each column and row has its own properties. Use the column and row headers to change column/row properties. Field Description
Column/Row The index of the column/row. Use the arrow buttons (or Alt+Left, Alt+Right, Alt+Up, Alt+Down keys) to edit the properties of the previous or next column/row. Default alignment The default alignment of the components within a column/row. Used if the value of the constraints properties "h align" or "v align" is DEFAULT. Specifies how TableLayout computes the width/height of a column/row.
Size
Tip: The column/row context menu allows you to alter many of these options for multi-selections.
In contrast to the TableLayoutConstraints API, which uses [column1,row1,column2,row2] to specify the location and size of a component, JFormDesigner uses the usual [x,y,width,height] notation. Tip: The component context menu allows you to alter the alignment for multi-selections.
- 110 -
9.13
VerticalLayout (SwingX)
The vertical layout manager places components vertically. The components are stretched horizontally to the width of the container.
VerticalLayout is part of the SwingX open source project and not part of the standard Java distribution. You must ship an additional library with your application. The JFormDesigner distribution does not include the SwingX library. For downloads, documentation and tutorials, visit swingx.java.net (or www.swinglabs.org).
- 111 -
10
JFormDesigner can generate and update Java source code. It uses the same name for the Java file as for the Form file. E.g.: C:\MyProject\src\com\myproject\WelcomeDialog.jfd (form file) C:\MyProject\src\com\myproject\WelcomeDialog.java (java file) Stand-alone: Before creating new forms, you should specify the locations of your Java source folders in the Project dialog. Then JFormDesigner can generate valid package statements. For the above example, you should add C:\MyProject\src. IDE plug-ins: The source folders of the IDE projects are used. If the Java file does not exist, JFormDesigner generates a new one. Otherwise it parses the existing Java file and inserts/updates the code for the form and adds import statements if necessary. Stand-alone: The Java file will be updated when saving the form file. IDE plug-ins: If the Java file is opened in the IDE editor, it will be immediately updated in-memory on each change in JFormDesigner. Otherwise it will be updated when saving the form file. JFormDesigner uses special comments to identify the code sections that it will generate/update. E.g.: // JFormDesigner - ... //GEN-BEGIN:initComponents // JFormDesigner - ... //GEN-END:initComponents The starting comment must contain GEN-BEGIN:<keyword>, the ending comment GEN-END:<keyword>. These comments are NetBeans compatible. The text before GEN-BEGIN and GEN-END (in the same line) does not matter. JFormDesigner uses the following keywords: Keyword name Description
initComponents Used for code that instantiates and initializes the components of the form. variables initI18n Used for code that declares the class level variables for components. Used for code that initializes localized component properties if option "Generate initComponentsI18n() method" is enabled in the Localization (Java Code Generator) preferences or "(form)" properties. Used for code that initializes bindings if option "Generate initComponentBindings() method" is enabled in the Localization (Java Code Generator) preferences or "(form)" properties.
initBindings
- 112 -
10.1
Nested Classes
One of the advanced features of JFormDesigner is the generation of nested classes. Normally, all code for a form is generated into one class. If you have forms with many components, e.g. a JTabbedPane with some tabs, it is not recommended to have only one class. If you hand-code such a form, you would create a class for each tab. In JFormDesigner you can specify a nested class for each component. You do this in the Code Generation category in the Properties view. JFormDesigner automatically generates/updates the specified nested classes. This allows you to program more object-oriented and makes your code easier to read and maintain.
Components having a nested class are marked with a Example source code:
public class NestedClassDemo extends JPanel { public NestedClassDemo() { initComponents(); }
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY tabbedPane = new JTabbedPane(); tab1Panel = new Tab1Panel(); tab2Panel = new Tab2Panel(); //======== this ======== setLayout(new BorderLayout()); //======== tabbedPane ======== { tabbedPane.addTab("tab 1", tab1Panel); tabbedPane.addTab("tab 2", tab2Panel); } add(tabbedPane, BorderLayout.CENTER); // JFormDesigner - End of component initialization }
//GEN-BEGIN:initComponents
//GEN-END:initComponents
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JTabbedPane tabbedPane; private Tab1Panel tab1Panel; private Tab2Panel tab2Panel; // JFormDesigner - End of variables declaration //GEN-END:variables //---- nested class Tab1Panel ----------------------------------------------------private class Tab1Panel extends JPanel { private Tab1Panel() { initComponents(); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY label2 = new JLabel(); textField1 = new JTextField(); CellConstraints cc = new CellConstraints();
//GEN-BEGIN:initComponents
- 113 -
//======== this ======== setBorder(Borders.TABBED_DIALOG_BORDER); setLayout(new FormLayout( ... )); //---- label2 ---label2.setText("text"); add(label2, cc.xy(1, 1)); //---- textField1 ---add(textField1, cc.xy(3, 1)); // JFormDesigner - End of component initialization } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JLabel label2; private JTextField textField1; // JFormDesigner - End of variables declaration //GEN-END:variables } //---- nested class Tab2Panel ----------------------------------------------------private class Tab2Panel extends JPanel { private Tab2Panel() { initComponents(); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY label3 = new JLabel(); checkBox1 = new JCheckBox(); CellConstraints cc = new CellConstraints(); //======== this ======== setBorder(Borders.TABBED_DIALOG_BORDER); setLayout(new FormLayout( ... )); //---- label3 ---label3.setText("text"); add(label3, cc.xy(1, 1)); //---- checkBox1 ---checkBox1.setText("text"); add(checkBox1, cc.xy(3, 1)); // JFormDesigner - End of component initialization } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JLabel label3; private JCheckBox checkBox1; // JFormDesigner - End of variables declaration //GEN-END:variables } }
//GEN-END:initComponents
//GEN-BEGIN:initComponents
//GEN-END:initComponents
When changing the nested class name in the Code Generation category, JFormDesigner also renames the nested class in the Java source code. When removing the nested class name, then JFormDesigner does not remove the nested class in the Java source code to avoid loss of own source code.
- 114 -
10.2
Code Templates
When generating new Java files or classes, JFormDesigner uses the templates specified in the Preferences dialog. Template name File header Class Empty Class Event Handler Body Component Initialization Description Used when creating new Java files. Contains a header comment and a package statement. Used when generating a new (nested) class. Contains a class declaration, a constructor, a component initialization method and variable declarations. Used when generating a new empty class. This can happen, if all form components are contained in nested classes. Used for event handler method bodies. Replaces the variable ${component_initialization} used in other templates. Contains a method named initComponents. Invoke this method from your code to instantiate the components of your form. Feel free to change the method name if you don't like it. Used for code that initializes localized component properties if option "Generate initComponentsI18n() method" is enabled in the Localization (Java Code Generator) preferences or "(form)" properties. Used for code that initializes bindings if option "Generate initComponentBindings() method" is enabled in the Localization (Java Code Generator) preferences or "(form)" properties. Replaces the variable ${variables_declaration} used in other templates. A template for classes derived from java.awt.Dialog. Compared to the Class template, this has special constructors, which are necessary for java.awt.Dialog derived classes.
javax.swing.AbstractAction Used for nested action classes. You can change the existing templates or create additional templates in the Preferences dialog. It is possible to define your own templates for specific superclasses. Following variables can be used in the templates: Variable name ${date} ${user} ${package_declaration} Description Current date. User name. package statement. If the form is not saved under one of the source folders specified in the Project dialog, the variable is empty (no package statement will be generated). Name of the (nested) class. Context global global file header class class class class class class
${class_name}
${component_initialization} See template Component initialization. ${constructor_modifiers} ${extends_declaration} ${modifiers} ${variables_declaration} Modifiers of the constructor. Based on the class modifiers. The extends declaration of the class; empty if the class has no superclass. Modifiers of the (nested) class. You can specify the default modifiers in the Preferences dialog. See template Variables declaration.
- 115 -
11
The command-line tool allows you to run some commands (e.g. Java code generation) on many forms.
Available commands
Java Code Generation: Usually its not necessary to run the Java code generator from command-line because the Java code is automatically generated and updated while editing a form in JFormDesigner. However in rare cases it is useful to re-generate the Java code of JFormDesigner forms. E.g. if you want upgrade to JGoodies FormLayout 1.2, which introduced a new much shorter syntax for encoded column and row specifications. Externalize strings: If you have to localize many existing non-localized forms, then this command does the job very quickly.
Requirements
You need an installation of the JFormDesigner stand-alone edition. If you usually use one of the IDE plug-ins, then simply download the stand-alone edition and install it.
Preferences
To specify preferences for the command-line tool, you should create a stand-alone edition project, enable and set project specific settings and pass the project .jfdproj file to the command-line tool. If you usually use the JFormDesigner stand-alone edition and already have a .jfdproj file, then you can use it for the command-line tool. Otherwise start the JFormDesigner stand-alone edition and create a new project. If you don't use a project, then the command-line tool uses the preferences store of the stand-alone edition. If you use one of the IDE plug-ins of JFormDesigner, you have to start the stand-alone edition and set the necessary preferences. To transfer JFormDesigner preferences from an IDE to the stand-alone edition, you can use the Import and Export buttons in the Preferences dialogs. Make sure that the Code Style preferences are correct because they are not transfered from the IDE.
Description Specifies the JAR that contains the command-line tool. This is a standard argument of the Java application launcher.
com.jformdesigner.application.CommandLineMain The class name of the command-line tool. --generate --i18n-externalize Generate Java code for the given forms or folders. Externalize strings in the given forms or folders. This requires that you've specified Source Folders in the used project.
- 116 -
Description Execute the given command, but do not save modifications. Only shows what would happen. This option enables --verbose. Prints file names of processed .jfd and .java files to the console. Recursively process folders. Only used for --i18n-externalize. The resource bundle name used to store strings. You can use variables {package} (package name of form) and {basename} (basename of form). Default is "{package}.Bundle", which creates Bundle.properties in same package as the form. This option is ignored when processing already localized forms. Only used for --i18n-externalize. The prefix for generated key. You can use variable {basename} (basename of form). Default is "{basename}". This option is ignored when processing already localized forms. Only used for --i18n-externalize. Set the auto-externalize option in the processed forms. Default is true. Optional JFormDesigner stand-alone edition project used to extend the classpath and to specify other preferences. Useful when using custom components. List of folders or .jfd files. If a folder is specified, all .jfd files in the folder are processed.
--key-prefix=<keyPrefix>
--auto-externalize=<true|false>
<project-path>/MyProject.jfdproj
The options and parameters are processed in the order they are passed. An option is always used for subsequent parameters, but not for preceding ones. E.g. "src1 --recursive src2" processes src2 recursively, but not src1. It is also possible to specify options or projects more than once. E.g. " project1.jfdproj src1 project2.jfdproj src2" uses project1.jfdproj for src1 and project2.jfdproj for src2.
Examples
Generate code for a single form:
cd C:\MyProject java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar com.jformdesigner.application.CommandLineMain --generate src/com/myproject/MyForm1.jfd
- 117 -
Generate code for all forms in a project that use custom components:
cd C:\MyProject java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar;classes;swingx.jar com.jformdesigner.application.CommandLineMain --generate --recursive src
Externalize strings in all forms of the src folder and use one bundle file per form and no key prefix:
cd C:\MyProject java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar com.jformdesigner.application.CommandLineMain --i18n-externalize --recursive --bundle-name={package}.{basename} --key-prefix= MyProject.jfdproj src
Ant
Although we don't provide a special task for Ant, it is easy to invoke the JFormDesigner command-line tool from an Ant script. The <classpath> element makes it easy to specify JARs and folders of custom components.
<property name="command_line_html__jfd-install-dir" value="C:/Program Files/JFormDesigner"/> <java classname="command_line_html__com.jformdesigner.application.CommandLineMain" fork="true" failonerror="true" logError="true"> <classpath> <pathelement location="${jfd-install-dir}/lib/JFormDesigner.jar"/> <pathelement location="myLibrary.jar"/> </classpath> <arg value="--generate"/> <arg value="--recursive"/> <arg value="src"/> </java>
- 118 -
12
Runtime Library
Note: If you use the Java code generator, you don't need this library. The open-source (BSD license) runtime library allows you to load JFormDesigner XML files at runtime within your applications. Turn off the Java code generation in the Preferences dialog or in the Project settings if you use this library. You'll find the library jfd-loader.jar in the redist folder (or plug-in) of the JFormDesigner installation; the source code is in jfd-loader-src.zip and the documentation is in jfd-loader-javadoc.zip. The API documentation is also available here: doc.formdev.com/jfd-loader/.
Classes
FormLoader provides methods to load JFormDesigner .jfd files into in-memory form models. FormCreator creates instances of Swing components from in-memory form models and provides methods to access components. FormSaver saves in-memory form models to JFormDesigner .jfd files. Can be used to convert proprietary form specifications to JFormDesigner .jfd files: first create a in-memory form model from your form specification, then save the model to a .jfd file.
Example
The following example demonstrates the usage of FormLoader and FormCreator. It is included in the examples distributed with all JFormDesigner editions.
public class LoaderExample { private JDialog dialog; public static void main(String[] args) { new LoaderExample(); } LoaderExample() { try { // load the .jfd file into memory FormModel formModel = FormLoader.load( "com/jformdesigner/examples/LoaderExample.jfd"); // create a dialog FormCreator formCreator = new FormCreator(formModel); formCreator.setTarget(this); dialog = formCreator.createDialog(null); // get references to components JTextField nameField = formCreator.getTextField("nameField"); JCheckBox checkBox = formCreator.getCheckBox("checkBox"); // set values nameField.setText("enter name here"); checkBox.setSelected(true); // show dialog dialog.setModal(true); dialog.pack(); dialog.show(); System.out.println(nameField.getText()); System.out.println(checkBox.isSelected()); System.exit(0); } catch(Exception ex) {
- 119 -
ex.printStackTrace(); } } // event handler for checkBox private void checkBoxActionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(dialog, "check box clicked"); } // event handler for okButton private void okButtonActionPerformed() { dialog.dispose(); } }
- 120 -
13
JavaBeans
What is a Java Bean? A Java Bean is a reusable software component that can be manipulated visually in a builder tool. JavaBean (components) are self-contained, reusable software units that can be visually composed into composite components and applications. A bean is a Java class that: is public and not abstract has a public "null" constructor (without parameters) has properties defined by public getter and setter methods. JFormDesigner supports: Visual beans (must inherit from java.awt.Component). Non-visual beans.
BeanInfo
JFormDesigner supports/uses following classes/interfaces specified in the java.beans package: BeanInfo BeanDescriptor EventSetDescriptor PropertyDescriptor PropertyEditor (incl. support for custom and paintable editors) Customizer If you are writing BeanInfo classes for your custom components, you can specify additional information needed by JFormDesigner using the java.beans.FeatureDescriptor extension mechanism. You can also use BeanInfo Annotations to specify these attributes without the pain of implementing BeanInfo classes. For examples using BeanInfo Annotations, example implementations of BeanInfo classes and PropertyEditors, take a look at the examples. BeanDescriptor Attributes Following attributes are supported in BeanDescriptor: Attribute Name isContainer Description Specifies whether a component is a container or not. A container can have child components. The value must be a Boolean. Default is false. E.g. beanDesc.setValue("isContainer", Boolean.TRUE); containerDelegate If components should be added to a descendant of a container, then it is possible to specify a method that returns the container for the children. JFrame.getContentPane() is a example for such a method. The value must be a String and specifies the name of a method that takes no arguments and returns a java.awt.Container. E.g. beanDesc.setValue("containerDelegate", "getContentPane"); layoutManager Allows the specification of a layout manager, which is used when adding the component to a form. If specified, then JFormDesigner does not allow the selection of a layout manager. The value must be a Class. E.g.
- 121 -
Attribute Name
persistenceDelegate Specifies an instance of a class, which extends java.beans.PersistenceDelegate, that can be used to persist an instance of the bean. E.g. beanDesc.setValue("persistenceDelegate", new MyBeanPersistenceDelegate()); PropertyDescriptor Attributes Following attributes are supported in PropertyDescriptor: Attribute Name category Description Specifies the property category to which the property belongs. JFormDesigner adds the specified category to the Properties view. The value must be a String. propDesc.setValue("category", "My Properties"); enumerationValues Specifies a list of valid property values. The value must be a Object[]. For each property value, the Object[] must contain three items: Name: A displayable name for the property value. Value: The actual property value. Java Initialization String: A Java code piece used when generating code. propDesc.setValue("enumerationValues", new Object[] { "horizontal", JSlider.HORIZONTAL, "JSlider.HORIZONTAL", "vertical", JSlider.VERTICAL, "JSlider.VERTICAL" }); extraPersistenceDelegates Specifies a list of persistence delegates for classes. The value must be a Object[]. For each class, the Object[] must contain two items: Class: The class for which the persistence delegate should be used. Persistence delegate: Instance of a class, which extends java.beans.PersistenceDelegate, that should be used to persist an instance of the specified class. Use the attribute "persistenceDelegate" (see below) to specify a persistence delegate for the property value. Use this attribute to specify persistence delegates for classes that are referenced by the property value. E.g. if a property value references classes MyClass1 and MyClass2: propDesc.setValue("extraPersistenceDelegates", new Object[] { MyClass1.class, new MyClass1PersistenceDelegate(), MyClass2.class, new MyClass2PersistenceDelegate(), }); imports Specifies one or more class names for which import statements should be generated by the Java code generator. This is useful if you don't use full qualified class names in enumerationValues or PropertyEditor.getJavaInitializationString(). The value must be a String or String[]. E.g. propDesc.setValue("imports", "com.mycompany.MyConstants"); propDesc.setValue("imports", new String[] { "com.mycompany.MyConstants", "com.mycompany.MyExtendedConstants" }); notMultiSelection Specifies whether the property is not shown in the Properties view when multiple components are selected. The value must be a Boolean. Default is false. E.g. propDesc.setValue("notMultiSelection", Boolean.TRUE); notNull Specifies that a property can not set to null in the Properties view. If true, the Set Value to null command is disabled. The value must be a Boolean. Default is false. E.g.
- 122 -
Attribute Name
notRestoreDefault
Specifies that a property value can not restored to the default in the Properties view. If true, the Restore Default Value command is disabled. The value must be a Boolean. Default is false. E.g. propDesc.setValue("notRestoreDefault", Boolean.TRUE);
persistenceDelegate
Specifies an instance of a class, which extends java.beans.PersistenceDelegate, that can be used to persist an instance of a property value. E.g. propDesc.setValue("persistenceDelegate", new MyPropPersistenceDelegate());
readOnly
Specifies that a property is read-only in the Properties view. The value must be a Boolean. Default is false. E.g. propDesc.setValue("readOnly", Boolean.TRUE);
transient
Specifies that the property value should not persisted and no code should generated. The value must be a Boolean. Default is false. E.g. propDesc.setValue("transient", Boolean.TRUE);
variableDefault
Specifies whether the default property value depends on other property values. The value must be a Boolean. Default is false. E.g. propDesc.setValue("variableDefault", Boolean.TRUE);
Design time
JavaBeans support the concept of "design"-mode, when JavaBeans are used in a GUI design tool, and "run"-mode, when JavaBeans are used in an application. You can use the method java.beans.Beans.isDesignTime() in your JavaBean to determine whether it is running in JFormDesigner or in your application.
Reload beans
JFormDesigner automatically reloads classes of custom JavaBeans when changed. So you can change the source code of used custom JavaBeans, compile them in your IDE and use them in JFormDesigner immediately without restarting. You can also manually reload classes: Stand-alone: Select View > Refresh Designer from the menu or press F5. IDE plug-ins: Click the Refresh Designer button ( Refresh does following: 1. Create a new class loader for loading JavaBeans, BeanInfos and Icons. 2. Recreates the form in the active Design view. ) in the designer tool bar.
- 123 -
14
Annotations
The @BeanInfo and @PropertyDesc annotations make it very easy to specifying BeanInfo information directly in the custom component. Its no longer necessary to implement extra BeanInfo classes. This drastically reduces time and code needed to create BeanInfo information. When using the JFormDesigner annotations, you have to add the library jfd-annotations.jar (from redist folder) to the build path of your project (necessary for the Java compiler). The documentation is in jfd-annotations-javadoc.zip. It is not necessary to distribute jfd-annotations.jar with your application. The API documentation is also available here: doc.formdev.com/jfd-annotations/
@BeanInfo
This annotation can be used to specify additional information for constructing a BeanInfo class and its BeanDescriptor. Example for specifying a description, an icon, property display names and flags, and property categories:
@BeanInfo( description="My Bean", icon="MyBean.gif", properties={ @PropertyDesc(name="magnitude", displayName="magnitude (in %)", preferred=true) @PropertyDesc(name="enabled", expert=true) }, categories={ @Category(name="Sizes", properties={"preferredSize", "minimumSize", "maximumSize"}), @Category(name="Colors", properties={"background", "foreground"}), } ) public class MyBean extends JCompoment { ... }
@PropertyDesc
This annotation can be used to specify additional information for constructing a PropertyDescriptor. This annotation may be used in a @BeanInfo annotation (see @BeanInfo.properties()) or may be attached to property getter or setter methods. If the getter method of a property is annotated, then the setter method of the same property is not checked for this annotation. Important: This annotation requires that the @BeanInfo annotation is specified for the bean class. Otherwise this annotation is ignored when specified at methods. Example for attaching this annotation to a property getter method:
@PropertyDesc(displayName="magnitude (in %)", preferred=true) public int getMagnitude() { return magnitude; }
- 124 -
@DesignCreate
This annotation can be used to mark a static method that should be invoked by JFormDesigner to create instances of the bean, which are then used in the JFormDesigner Design view. The annotated method must be static, must not have parameters and must return the instance of created bean. Example for using this annotation to initialize the bean with test data for the Design view:
public class MyBean extends JCompoment { @DesignCreate private static MyBean designCreate() { MyBean myBean = new MyBean(); myBean.setData( new SomeDummyDataForDesigning() ); return myBean; } public MyBean() { // ... } }
- 125 -
15
JFormDesigner supports and uses software provided by JGoodies Karsten Lentzsch. The JGoodies Forms framework support is very extensive. Not only the layout manager FormLayout is supported, also some important helper classes are supported: Borders, ComponentFactory and FormFactory (com.jgoodies.forms.factories). JGoodies Looks look and feels are built-in so that you can preview your forms using those popular look and feels. JGoodies Looks examples contains some useful components to build Eclipse like panels: JGoodies UIF lite.
When using one of these components, you have to add the library redist/jgoodies-uif-lite.jar to the classpath of your application. Or add the source code to your repository and compile it into your application. The source code is in redist/jgoodies-uif-lite-src.zip. The API documentation is also available here: doc.formdev.com/jgoodies-uif-lite/. IDE plug-ins: If you use one of the UIF lite components the first time, the JFormDesigner IDE plug-in ask you whether it should copy the required library (and its source code and documentation) to the IDE project and add it to the classpath of the IDE project. To add a toolbar to a SimpleInternalFrame, add a JToolBar to the Design view, select the SimpleInternalFrame, select the "toolBar" property in the Properties view and assign the toolbar to it.
- 126 -
16
A JFormDesigner installation includes example source code and redistributable files. Because JFormDesigner is available in several editions and each IDE plug-in has its own requirements regarding plug-in directory structure and installation location, the installation location of the examples and redistributables depends on the JFormDesigner edition. The tables below list the locations for each JFormDesigner edition.
Examples
The examples folder (or examples.zip archive) contains example source code and forms. See examples/README.html for details. Edition Stand-alone Location <jformdesigner-install>/examples/ Mac OS X: <JFormDesigner.app>/examples/ (right-click on JFormDesigner application and select "Show Package Contents" from the context menu to see contents of <JFormDesigner.app>) Eclipse plug-in <eclipse-install>/features/com.jformdesigner_x.x.x/examples.zip or <eclipse-install>/dropins/JFormDesigner-x.x-eclipse/features/ com.jformdesigner_x.x.x/examples.zip <user-home>/.IntelliJIdeaXX/config/plugins/JFormDesigner/examples.zip or <intellij-idea-install>/plugins/JFormDesigner/examples.zip Mac OS X: <user-home>/Library/Application Support/IntelliJIdeaXX/JFormDesigner/examples.zip JBuilder plug-in <jbuilder-install>/lib/ext/JFormDesigner/examples.zip
Redistributables
The redist folder contains the JFormDesigner Annontations Library, the JFormDesigner Runtime Library and 3rd party open source files (layout manager, beans binding, etc). See redist/README.html for information about licenses. Edition Stand-alone Location <jformdesigner-install>/redist/ Mac OS X: <JFormDesigner.app>/redist/ (right-click on JFormDesigner application and select "Show Package Contents" from the context menu to see contents of <JFormDesigner.app>) Eclipse plug-in <eclipse-install>/plugins/com.jformdesigner.redist_x.x.x or <eclipse-install>/dropins/JFormDesigner-x.x-eclipse/plugins/ com.jformdesigner.redist_x.x.x/ <user-home>/.IntelliJIdeaXX/config/plugins/JFormDesigner/redist/ or <intellij-idea-install>/plugins/JFormDesigner/redist/ Mac OS X: <user-home>/Library/Application Support/IntelliJIdeaXX/JFormDesigner/redist/ JBuilder plug-in <jbuilder-install>/lib/ext/JFormDesigner/redist/
- 127 -