JIDE Common Layer Developer Guide
JIDE Common Layer Developer Guide
JIDEBOXLAYOUT ........................................................................................................................................... 12
Code Example 1: .................................................................................................................................. 12
Code Example 2: .................................................................................................................................. 13
JIDEBORDERLAYOUT ...................................................................................................................................... 13
BORDERS ............................................................................................................................................... 15
PARTIALETCHEDBORDER ................................................................................................................................ 15
PARTIALLINEBORDER ..................................................................................................................................... 15
PARTIALGRADIENTLINEBORDER ....................................................................................................................... 15
TITLEDSEPARATOR......................................................................................................................................... 16
STYLEDLABEL ......................................................................................................................................... 17
RANGESLIDER ........................................................................................................................................ 22
TRISTATECHECKBOX ............................................................................................................................... 24
FEATURES OF TRISTATECHECKBOX.................................................................................................................... 24
CLASSES, INTERFACES AND DEMOS ................................................................................................................... 24
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
JIDESPLITPANE ....................................................................................................................................... 25
JIDETABBEDPANE ................................................................................................................................... 27
JIDESCROLLPANE.................................................................................................................................... 32
MARQUEEPANE ..................................................................................................................................... 33
SIMPLESCROLLPANE............................................................................................................................... 35
FEATURES OF SIMPLESCROLLPANE.................................................................................................................... 35
CLASSES, INTERFACES AND DEMOS ................................................................................................................... 35
CHECKBOXLIST ....................................................................................................................................... 36
FEATURES OF CHECKBOXLIST........................................................................................................................... 36
CLASSES, INTERFACES AND DEMOS ................................................................................................................... 36
CODE EXAMPLES ........................................................................................................................................... 37
CHECKBOXTREE ...................................................................................................................................... 39
FOLDERCHOOSER ................................................................................................................................... 41
2
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
JIDEBUTTON........................................................................................................................................... 49
JIDESPLITBUTTON .................................................................................................................................. 50
JIDELABEL .............................................................................................................................................. 50
FEATURES .................................................................................................................................................... 52
HOW TO EXTEND SEARCHABLE ......................................................................................................................... 54
RESIZABLE.................................................................................................................................................... 56
SEVERAL RESIZEABLE EXAMPLES ....................................................................................................................... 57
POPUP ................................................................................................................................................... 58
OPTIONS ..................................................................................................................................................... 59
INTELLIHINTS ......................................................................................................................................... 60
AUTOCOMPLETION ................................................................................................................................ 63
OVERLAYABLE ........................................................................................................................................ 63
3
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
4
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
components from this project commercially. They are already in production quality when they
are included in this open source project.
5
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
components are part of it too. After you read this developer guide, you can dive into the demo
and the demo source code to learn more about JCL and see JCL in action.
Package Structure
The table below lists the packages in the JIDE Common Layer. All packages are in jide-oss-
<version>.jar or [Link] if you are a paid JIDE user1.
Packages Description
[Link] Common components.
[Link] Icon related classes
[Link] Various Comparators. They all implement interface
[Link]. ObjectComparatorManager provides
a central place to register those comparators.
[Link] Various ObjectConverters which can convert an object
to/from String. ObjectConverterManager provides a central
place to register those converters.
[Link] Various ObjectGroupers which can group several values
into a named group. ObjectGrouperManager provides a
central place to register those groupers.
[Link] Popup component
[Link] Animation related classes
[Link] IntelliHints related classes
[Link] Dialog related classes
[Link] A new data type of Range which is used in JIDE Gantt
Charts and JIDE TreeMap
[Link] Validation related classes
[Link] Several spinner components
A general comment on our naming convention: If the class is modified from or based on an
existing Swing/AWT class, and serve the same purpose of the existing Swing component, we
prefix the original Swing/AWT class name with Jide - for example, JideTabbedPane (you can tell
that it is based on JTabbedPane from the name). If it’s a completely new component that
1If you are a paid JIDE product user, you should use [Link] instead of the [Link] for JCL portion.
The [Link] includes everything inside [Link] and a few more classes that are not public APIs but are
used by other JIDE products.
6
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
doesn’t exist in Swing/AWT then we don’t prefix anything - for example, Calculator etc. There
are also cases that a class extends an existing Swing component but the purpose is changed, if
so, we will not use Jide- prefix either, for example, RangeSlider.
We will add more and more components to JIDE Common Layer in the future and we will
keep the same package organization. If the component is complex enough or there are a group
of components which share a common feature, there will be a separate package for it. If it is a
very small component, we probably will put it under [Link].
List of Components
In the tables below, we listed all the components and utility classes in JIDE Common Layer.
The bold classes below are the ones that are covered in details in this developer guide.
LAYOUT MANAGERS
BORDERS
7
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
lines.
CheckBoxList JList A JList that supports check boxes as the list cell.
CheckBoxTree JTree A JTree that supports check boxes as the tree cell.
8
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
9
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
JTextComponent.
Searchable Searchable implements the quick search feature on JList, JTable, JTree and many
other components.
Resizable Resizable can be used to make a component resizable. Right now we have it
implemented for JDialog (undecorated), JWindow and JFrame (undecorated).
Sticky Sticky is a helper class to make JList or JTree or JTable changing selection when
mouse moves
TintFilter TintFilter is an image filter that tints the image with a color.
MaskFilter MaskFilter is an image filter that replaces one color in an image with another color.
RolloverIcon RolloverIcon provides the expanded and collapsed tree icons that has rollover and
fade effect. However it can be used to implement icon for any other purpose, not
just the tree icons.
IconSetManager IconSetManager makes it easy to switch between different icon sets that are in
JIDE Basic and Network Icon Sets.
IconSet IconSet is a class which works with JIDE Basic Icon Set. It defines 141 icons in 12
sections in this class.
NetworkIconSet NetworkIconSet is a class which works with JIDE Network Icon Set. It defines 72
icons in 6 sections in this class.
INTERFACES
10
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
CheckBoxListWithSelectable.
Overlayable To indicate a component can add additional components as overlays which can be
used for error indicator, validation warning etc purposes. It is very similar to JLayer
that was introduced in JDK7. We would recommend you to use JLayer instead if
you are using JDK7.
Prioritized To indicate a data type that has priority. It is only implemented by CellStyle in JIDE
Grids
WildcardSupport A common interface for the wildcard support. It is used in many components
related to searching and filtering.
DelegateAction DelegateAction is an Action class that can be implemented then it can replace the
action on a component. DelegateAction will be triggered first then the original
action will be triggered depending on the return value from DelegateAction.
SelectAllUtils SelectAllUtils is a utility class to select all the text in a text component when the
component first time receives focus.
TimeUtils
11
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Layout Managers
JideBoxLayout
As its name indicates, the JideBoxLayout class is similar to Swing’s BoxLayout.
Similar to BoxLayout, JideBoxLayout lays components out either vertically or horizontally.
Unlike BoxLayout however, there is a constraint associated with each component, set to either
FIX, FLEXIBLE, or VARY. If the constraint is set to FIX then the component’s width (or height if the
JideBoxLayout is vertical) will always be the preferred width. By contrast, although FLEXIBLE
components try to keep the preferred width, they will shrink proportionally if there is not
enough space. Finally, VARY components will expand in size to fill whatever width is left.
Although you can add multiple FIX or FLEXIBLE components, only one VARY component is
allowed.
Code Example 1:
This sample has three buttons; the first one is FIX and the second and third ones are
FLEXIBLE.
Original:
After resizing:
12
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Code Example 2:
This example has one FIX button, one FLEXIBLE button, and one VARY button.
Original:
After resizing, the VARY component gets all the extra width:
After resizing to make it smaller, when the VARY component reaches its minimum width,
the FLEX component will start to resize and the FIX component will never resize:
JideBorderLayout
JideBorderLayout is almost the same as the standard Swing BorderLayout except that the
NORTH and SOUTH component’s width is the same as the CENTER component, as shown
overleaf. Please note the difference between BorderLayout and JideBorderLayout.
13
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
In AWT BorderLayout, the north and south components take all of the horizontal space that
is available.
By contrast, in JideBorderLayout the north and south components only take the same
horizontal space as the center component.
14
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Borders
PartialEtchedBorder
PartialEtchedBorder is an EtchedBorder that only paints the etched border on the partial
sides. The screenshot below paints only on the north side.
PartialLineBorder
PartialLineBorder is a LineBorder that only paints the line border on the partial sides. The
screenshot below paints only on the north side.
PartialGradientLineBorder
PartialGradientLineBorder is a border that only paints a gradient line border on the partial
sides. The screenshot below paints only on the north side.
15
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
TitledSeparator
The TitledSeparator is not a Border. The reason we included it here is it can archive the
same effect as PartialEtchedBorder, PartialLineBorder and PartialGradientLineBorder. You can
decide which one to use depending on if you want to implement the feature as border or as a
separate component.
16
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
StyledLabel
Features of StyledLabel
StyledLabel is an enhanced version of JLabel to display text in different colors and styles with
several line decorations. It also supports automatic line wrapping.
JLabel is simple and fast but has very limited features. For example, you can't use different
colors to draw the text. Changing the foreground will affect the whole text. You may argue
JLabel can use HTML tag to display text in different colors. Sure, but there are two drawbacks.
First it is very slow2. Secondly, it is buggy3. Comparing with HTML JLabel, StyledLabel is 20 to 40
times faster based on our performance test. Another solution is to use JTextPane. JTextPane is
powerful and can display text in different colors. But in the cases like cell renderers, JTextPane is
obviously an overkill.
Here is the list of features that StyledLabel support.
Uses different font styles to display the text.
Uses different colors to display the text
2
You can see [Link] in examples\B15. StyledLabel folder to see
a performace test of HTML JLabel and StyledLabel.
3
See bug report at [Link] Sun
claimed it is fixed but it is not as another user pointed it out at the end. If you run the test case
provided by original submitter, you will immediately notice the tree node disappeared when you
click on the tree nodes. This bug is actually one of the main reasons we decided to create
StyledLabel.
17
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
StyleRange This is the class to define the style. Since the style is defined based
([Link]) for a range of text in StyledLabel, that’s why it is called StyleRange.
Demos
18
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
StyleRange
StyleRange describes a style for a range of text. For example, to display a StyledLabel like
“JavaTM”, the StyleRange will be
It means “starting from the 4th characters, for the next 2 characters, use PLAIN font to draw
the text and apply superscript style”.
If StyledLabel has no StyleRange set, StyledLabel will behave exactly the same as JLabel. You
can also add multiple StyleRanges as long as those ranges don’t overlap with each other. If you
add a new StyleRange that overlaps with previously set StyleRanges, the new StyleRange will be
ignored.
Here is the information you can set to StyleRange.
int fontStyle The font style. The valid values are [Link], [Link],
[Link], or [Link] | [Link].
Stroke lineStroke The line stroke. If there are lines in the additional style, the line
stroke will be used to paint the line.
int additionalStyle The additional style. This is the property you set to get all kinds
of styles. The valid values are
STYLE_STRIKE_THROUGH
STYLE_DOUBLE_STRIKE_THROUGH
STYLE_WAVED
STYLE_UNDERLINED
STYLE_DOTTED
STYLE_SUPERSCRIPT
STYLE_SUBSCRIPT
They are all defined in StyleRange as constants. You can even
use a combination of several styles by using “|” as long as they
make sense. For example, you can use both strike through and
19
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
StyledLabel
StyledLabel has several methods to change StyleRange. The most used one is
This method will set one StyleRange to StyledLabel while keeping any other StyleRanges if
they are set earlier.
There are also two methods to allow you quickly add several StyleRanges at once. The only
difference is the first one will clear StyleRanges that was set earlier.
All the methods above will fire property change event on property “styleRange”. The
property name is defined as StyleRange.PROPERTY_STYLE_RANGE.
StyledLabel only has one new property called “ignoreColorSettings”. If this property is true,
the color setting defined StyleRange will be ignored and the default foreground will be used to
paint the text and color. The color settings include font color and line color. The reason we need
this property is for cell renderer. Cell renderer, when selected, need to use selection
background. Selection background is usually defined by specific LookAndFeel, there is no way
you can guarantee the color you used in StyleRange works well with the selection background.
To avoid color confliction, we will set this property to true if the cell is selected.
You will know exactly what this property is for by looking at the two screenshots below.
Although we use red and gray color in the first cell, they become white (the default selection
foreground) when the cell is selected. You can imagine the gray color won’t look good on a blue
background.
Almost all the features provided by JLabel still work with StyledLabel. You can add icon. You
can set the alignment of the icon or the text or set text position. You can even set mnemonic
just like in JLabel. However, you need to be aware that if you also use certain underlined line
style, the mnemonic indicator might be conflict with the underline.
20
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Code Examples
1. Display “TM” as superscript in string “JavaTM”.
[Link](new StyledTreeCellRenderer() {
21
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
protected void customizeStyledLabel(JTree tree, Object value, boolean sel, boolean expanded, boolean
leaf, int row, boolean hasFocus) {
[Link](tree, value, sel, expanded, leaf, row, hasFocus);
String text = getText();
// here is the code to customize she StyledLabel for each tree node
}
});
RangeSlider
Features of RangeSlider
RangeSlider extends JSlider but it allows user to choose two values to form a range.
Here is the list of features that RangeSlider support.
22
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Allow to choose lower value and upper value separately to form a range
Allow to move both lower value and upper value at the same time
Support both horizontal and vertical orientation
Support several L&Fs (Metal, Windows, Aqua, Synth, GTK etc.) and can be extended to
support other L&Fs.
Demos
Code Examples
1. Creates a RangeSlider with certain min/max/lower/upper value
23
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
[Link](true);
TristateCheckBox
Features of TristateCheckBox
TristateCheckBox extends JCheckBox to add a 3rd state to indicate the check box is partially
selected.
Here is the list of features that TristateCheckBox support.
Allow a 3rd state for the check box
Can be used as a cell renderer in a JList, JTree or JTable
Support several L&Fs (Metal, Windows, Aqua, Synth, GTK etc.) and can be extended to
support other L&Fs.
Demos
Code Examples
1. Creates a TristateCheckBox and set it to the 3rd state.
24
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
int state = [Link]();
switch (state) {
case TristateCheckBox.STATE_MIXED:
// mixed state
break;
case TristateCheckBox.STATE_UNSELECTED:
// unselected state
break;
case TristateCheckBox.STATE_SELECTED:
// selected state
break;
}
}
});
JideSplitPane
JSplitPane is a useful Swing component but it has one major limitation: it can only split into
two panes. If you want to split into three panes, you have to use two JSplitPanes. That may be
OK in most cases, but if you want to split it into four or five or more panes then you will quickly
get into trouble, maintaining so many JSplitPanes. As you can see in JIDE Docking Framework,
we need to be able to split a panel into any number of panes4. JSplitPane obviously cannot
meet this need gracefully, so we developed JideSplitPane.
4You can refer to a bug in Java website for information on this particular issue.
[Link]
25
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Above is an example of a JideSplitPane, which is split into three parts. Each divider can be
moved using the mouse, to resize the components either side of it.
JideSplitPane can split either horizontally or vertically, using the two identifiers defined in
JideSplitPane as HORIZONTAL_SPLIT and VERTICAL_SPLIT. You can either specify the orientation
in the constructor or call setOrientation after it is constructed.
Call addPane(Component) or insertPane(Component, int) or add(Component) to add a new
component. The underlying layout is JideBoxLayout, so you can specify the constraints as VARY,
FLEXIBLE or FIX when you call add(Component, Object constraint).
By default, the size of the divider is 3 pixels. You can either change this by calling
setDividerSize(), or you can change it globally in UIDefaults using the key
“[Link]”. You can also change the border and background color of the divider
in UIDefaults using “[Link]” and “[Link]”.
In JSplitPane, you can call set the divider location by calling setDividerLocation(). You can
find this method on JideSplitPane too. However, the behavior is different. If the JideSplitPane is
displayed on screen, setDividerLocation will change the divider location correctly. If the
JideSplitPane has never been displayed before, this method call will have no effect. The reason is
setDividerLocation changes underlying layout directly. If the JideSplitPane is never displayed, the
underlying layout is not initialized properly, thus no effect. This is the correct way to change the
initial divider location. The divider location is determined by the preferred size of panes. So
instead of setting the location directly, you can set the preferred size of each pane to control the
dividers’ location. For example, if the preferred width of three panes in HORIZONTAL _SPLIT
JideSplitPane is 200, 300, 500 respectively, then the two dividers will be at 20% and 50% of the
total width of JideSplitPane.
26
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Continuous Layout refers to painting during drag and drop actions. If this is set to true, then
the child components are continuously redisplayed and laid out while moving a window. The
default value of this property is false, meaning that only an outline is displayed, which provides
much better performance. You can change this with setContinuousLayout(boolean).
Demos
JideTabbedPane
JideTabbedPane is similar to JTabbedPane; the differences are that JideTabbedPane:
Has many tab shapes you can choose from. Currently it has
o SHAPE_WINDOWS
o SHAPE_VSNET
o SHAPE_BOX
o SHAPE_OFFICE2003
27
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
o SHAPE_FLAT
o SHAPE_ECLIPSE
o SHAPE_ECLIPSE3x
o SHAPE_EXCEL
o SHAPE_ROUNDED_VSNET
o SHAPE_ROUNDED_FLAT
o SHAPE_WINDOWS_SELECTED.
Has different color themes to choose from. Currently it supports four different themes.
o COLOR_THEME_WIN2K
o COLOR_THEME_OFFICE2003
o COLOR_THEME_VSNET
o COLOR_THEME_WINXP
It even has a special OneNote color theme which is available as part of
COLOR_THEME_OFFICE2003.
28
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
o RESIZE_MODE_FIT: it shrinks tab size so that all tabs can fit in one row.
o RESIZE_MODE_FIXED: All tabs have a fixed size which you can define it yourself.
Each tab, no matter how long the title is, has the same size. It will not change its
size when tabbed pane size changes. So in order to select any tab, you still get
scroll left/right and tab list button as in RESIZE_MODE_NONE.
29
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Has an option to hide the tab area if there is only one component in a tabbed pane. This
is a feature used by JIDE Docking Framework.
Has an option to show a “close" button on the corner, on the tab, or on the selected
tab. This is very useful especially each tab is a document in DocumentPane. To use this
option, you need to call the following two calls. If you never call
setShowCloseButtonOnTab, a default value will be used by reading it from L&F. For
example, in VSNET L&F, the value is false. In Eclipse L&F, the value is true. So if you want
to set it freely, you must disable the L&F by setUseDefaultShowCloseButtonOnTab to
false. Then whatever value you set to setShowCloseButtonOnTab will be used.
[Link](false);
[Link](true);
JideTabbedPane also supports inline tab title editing. By default, this feature is disabled.
You need to enable it by calling setTabEditingAllowed(true). If enabled, user can double
click on any tab to start editing the title. See below.
30
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Demos
[Link] Color One of the colors used to paint the tab border
[Link] Color One of the colors used to paint the tab border
[Link] Color One of the colors used to paint the tab border
[Link] Color One of the colors used to paint the tab border
[Link] Insets The insets of the area where all the tabs are
[Link] Font The font used to draw the text of the selected tab
31
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
JideScrollPane
Features of JideScrollPane
Figure 1 JideScrollPane
Figure 2 JScrollPane
32
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Demos
MarqueePane
Features of MarqueePane
33
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Scrolls and stays. For example, when you scroll a text, it can scroll line by line and stay
for a while on each line so that the full text on that line can be read.
Demos
Code Examples
1. Scroll a long label horizontally when there isn’t enough size to show the full content
2. Scroll several status messages line by line and it stays on each line
34
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
SimpleScrollPane
Features of SimpleScrollPane
SimpleScrollPane extends JScrollPane. There is no scroll bar. It just uses four scroll buttons to
do the scrolling.
Here is the list of features that SimpleScrollPane supports.
No more scroll bars. It uses four buttons to scroll the content.
Instead of clicking on the scroll buttons, user can put mouse over the button and it will
scroll automatically.
The scroll buttons can be customized to always show, show as needed or never show.
Demos
35
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
CheckBoxList
Features of CheckBoxList
CheckBoxList is a special JList which uses JCheckBox as the list cell renderer. In addition to
regular JList's features, it also allows you select any number of rows in the list by selecting the
check boxes.
To select an element, user can mouse click on the check box, or select one or several rows
and press SPACE key to toggle the check box selection for all selected rows.
Here is the list of features that CheckBoxList support.
Check or uncheck each row.
Check or uncheck multiple rows by selecting them first
Still supports customized cell renderer as before. The cell renderer will be the part to
the left of the check box (when it’s left-to-right orientation).
5 Due to a design change, there are currently two working versions for CheckBoxList. The first one is just called
CheckBoxList. This one used the same design as CheckBoxTree and uses a DefaultListSelectionModel as the selection
model to keep track of which check boxes are checked. The second implementation is called
CheckBoxListWithSelectable. It stored the check box state information in ListModel by converting the element in the
ListModel to Selectable.
36
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
CheckBoxListCellRenderer The list cell renderer which uses check box as cell renderer.
([Link])
CheckBoxListWithSelectable
([Link])
Demos
Code Examples
1. To create a CheckBoxList. There is no difference from creating a regular JList.
or
37
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
[Link]();
[Link]();
CheckBoxList has its cell renderer which has check box. However, it doesn’t prevent you
from setting your own cell renderer. As you can see from the code above, the way to set a new
cell renderer is just like before. CheckTreeList will use the new cell renderer and add check box
before it. The difference is if you call getCellRenderer(), you will not get the cell renderer you set
but get the check box cell renderer. You can use getActualCellRenderer(), which is a new method
we added, to get the actual cell renderer you set.
6. Define your own ListModel that works with CheckBoxList.
CheckBoxList doesn’t keep the check box selection state in itself. All the selection
information is kept in Selectable object in the ListModel. Good thing about this approach is the
selection model will never go out of sync with data model. Bad thing is the data model needs to
be changed to support it. However, this change should be trivial in most cases.
38
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
CheckBoxTree
Features of CheckBoxTree
CheckBoxTree is a special JTree which uses JCheckBox as the tree renderer. In addition to
regular JTree's features, it also allows you select any number of tree nodes in the tree by
selecting the check boxes.
To select an element, user can mouse click on the check box, or select one or several tree
nodes and press SPACE key to toggle the check box selection for all selected tree nodes.
Here is the list of features that CheckBoxTree support.
Check or uncheck each tree node.
Check or uncheck multiple tree nodes by selecting them first
Supports dig-in mode
Still supports customized cell renderer as before. The cell renderer will be the part to
the left of the check box (when it’s left-to-right orientation).
39
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
CheckBoxTreeCellRenderer The tree cell renderer which uses check box as cell renderer.
([Link])
Demos
Code Examples
7. To create a CheckBoxTree. There is no difference from creating a regular JTree.
[Link]().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
// your code here.
}
});
The treePaths will be the list of tree path that are checked.
10. Change the dig-in mode.
[Link]().setDigIn(true/false);
If the CheckBoxTree is in dig-in mode, checking the parent node will check all the children.
Correspondingly, getSelectionPaths() will only return the parent tree path. If not in dig-in mode,
each tree node can be checked or unchecked independently.
11. Change the cell renderer for CheckBoxTree.
40
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
CheckBoxTree has its cell renderer which has check box. However, it doesn’t prevent you
from setting your own cell renderer. As you can see from the code above, the way to set a new
cell renderer is just like before. The checkBoxTree object will use the new cell renderer and add
check box before it. The difference is if you call getCellRenderer(), you will not get the cell
renderer you set but get the check box cell renderer. You can use getActualCellRenderer(),
which is a new method we added, to get the actual cell renderer you set.
FolderChooser
Features of FolderChooser
41
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Demos
Code Examples
1. Show an Open folder chooser dialog
42
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Standard Dialog
StandardDialog extends JDialog. In addition to JDialog, it can handle a couple of things that
all dialogs must handle anyway, such as layout, escape and enter key, initial focused component
etc.
We certainly can be creative when designing a dialog. Just because UI designers are creative,
that’s how we see more and more new controls. However sometimes we’d better follow the
convention. For example, I’ve seen a dialog layout as below with OK and Cancel on top.
You might argue it’s easy for user to reach OK and Cancel buttons. However in most culture,
users get used to look from top to bottom and from left to right. User wants to see what’s in
dialog first before they click on OK or Cancel button. This dialog obviously breaks the flow.
The two screenshots below show the normal layout of a dialog. On top, you can put a
banner panel. Button panel should be either on bottom or on right. Content panel is always in
the center. These layouts match the logic flow when people read.
43
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
It might be tedious to layout those three panels every time creating a dialog. StandardDialog
will layout automatically for you.
StandardDialog is an abstract class; you implement three methods. After you implemented
these three methods, StandardDialog will put them at the right places.
Almost all UI guidelines require dialog to handle ESC key and ENTER key correctly. In modal
dialog, ESC key should trigger the Cancel button and ENTER should trigger the default button.
StandardDialog also make this easier by allowing you to set default action and cancel action.
Usually when a dialog is shown, a component in that dialog should have focus. By default,
Swing doesn’t set any component focus. It is not that straightforward if you try to do it yourself
because you can set focus to a component only when a component is visible. With the help of
StandardDialog, it’s never being easier. All you need to do is during createContentPanel(), call
setInitFocusedComponent() to set the initial focused component to whatever you want.
We promise that whenever we find some interesting or useful stuffs, we will continuously
enhance StandardDialog. That’s all about StandardDialog so far. Simple, right? Yes. Even though
it’s simple, when you code using simple StandardDialog, your code will become more organized
and all your dialogs will look more consistent. Not only that, we also provide several
components to make it creation of each methods easier.
Banner Panel
BannerPanel is very useful to display a title, a description and an icon. It can be used in
dialog to show some help information or display a product logo in a nice way. You can also set
background of BannerPanel using Paint.
This screenshot below shows three examples that banner panel can do.
44
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
45
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Button Panel
We created ButtonPanel class in order to lay out buttons easily in any dialogs. It looks like a
very easy thing to do, but when you really think about it, it turns out not so easy. There are two
issues ButtonPanel try to solve – button width and button order.
Button Width
The problem arose when someone designed a panel like this. Notices the button widths are
different.
I hope we all agree that this screenshot above doesn’t look good. Not only it doesn’t look
good, but also the small size button is hard to click on. People realized that and argued that all
buttons in the same button panel should have the same width. See below for the result. Most
existing implementation of button panel did in this way.
With buttons at the same width, the panel certainly looks much better. However, when
dealing with several buttons with text of one of them is much longer than other’s, the problem
comes up. See below for an example. This one is from GNOME design document [GHIG].
“Close without Saving” is much longer than the other two buttons. Since all buttons should
have the same width, the “Cancel” and “Save” are forced to have the same width even though
it’s not really necessary. You can see the screen gets really crowd and will soon run out of
spaces. It might get worse after localization if “Close with Saving” is even longer in certain some
languages.
Mac OS X takes a different approach to handle this. See below. [AHIG]
Even though buttons have different width, this one looks better than the GNOME one.
46
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
It seems there are some contradictions here, isn’t it? It’s not necessary that all buttons
should have the same width. However all buttons should have the same minimum width. In
fact, this convention is followed on several OS. On Windows, the minimum button width is 75
pixels. On Mac OS X, it is 69 pixels. If the preferred width of button is less than the minimum,
minimum width should be used.
To implement this requirement in ButtonPanel, we added setSizeContraint() method. If you
pass in ButtonPanel.SAME_SIZE, all buttons will have the same width. If you pass in
ButtonPanel.NO_LESS_THAN, the button width will be no less than the minimum width. The
actual minimum width is different with different LookAndFeel.
Please note, ButtonPanel allows you to layout button horizontally and vertically. The
setSizeContraint() method only has effect when the buttons are laid out horizontally. If buttons
are laid out vertically, the setSizeContraint() will be ignored and ButtonPanel.SAME_SIZE is
always used. Knowing this drawback of vertical button panel, we suggest you use horizontal
button panel as possible as you can. On Mac OS X, it is very rare to see a vertical button panel.
On Windows, vertical button panels are used in some dialogs design but are much fewer than
horizontal ones.
47
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Taking the screenshot above as an example, if the button panel is left-alignment, the order
is “ACO”. This is a typical order of buttons on Windows.
On Mac OS X, the order is “CA” with right alignment and “HO” on the opposite side. So in
this case, the order “CA” and the opposite order is “HO”.
"[Link]", "ACO",
"[Link]", "H",
"[Link]", new Integer(6),
"[Link]", new Integer(6),
"[Link]", new Integer(75),
Java LookAndFeel
"[Link]", "ACO",
"[Link]", "H",
"[Link]", new Integer(5),
"[Link]", new Integer(5),
"[Link]", new Integer(57),
Mac AquaLookAndFeel
"[Link]", "CA",
"[Link]", "HO",
"[Link]", new Integer(6),
"[Link]", new Integer(12),
"[Link]", new Integer(69),
48
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
So if you want to use ButtonPanel, you just need to add buttons to it and specify the
category while adding. The ButtonPanel will use values from UIDefault to layout the button
correctly.
You can also change those values for a particular button panel instance. Those methods are
available to you. It will overwrite the value from UIDefaults.
setButtonOrder(String order)
setOppositeButtonOrder(String order)
setSizeContraint(SAME_SIZE / NO_LESS_THAN)
setGroupGap(int gap)
setButtonGap(int gap)
JideButton
JideButton was introduced to give JButton different styles. The main usage of the JideButton
is for the JToolBar or the CommandBar (from JIDE Action Framework).
The screenshot above shows what JideButtons look like under TOOLBAR_STYLE. There are three
more styles as shown above. They are TOOLBOX_STYLE, FLAT_STYLE and HYPERLINK_STYLE
respectively.
49
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
JideSplitButton
JideSplitButton is a combination of button and menu. There is a line in the middle of the
button that splits the button into two portions. The portion before the line is a button. User can
click on it and trigger an action. The portion after the line is a menu. User can click on it to show
a normal menu.
The screenshot below shows what JideSplitButtons look like under different styles. They are
TOOLBAR_STYLE, TOOLBOX_STYLE and FLAT_STYLE respectively.
JideLabel
JideLabel is a JLabel that can be used on JToolBar or CommandBar. It supports vertical
orientation. When it is used on a CommandBar, it will automatically toggle to vertical
orientation when the CommandBar is docked to the east or west side.
Searchable Components
JList, JComboBox, JTable, JTree, JTextComponent are five data-rich components. They can
be used to display a huge amount of data so searching function will be a very useful feature in
50
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
those components. By default, JList kind of supports searching. User can type in a key and the
list will automatically select that row whose first character matches with the typed key.
However, it can only match the first character. Therefore, the goal of this component is to make
all five components searchable6.
Searchable is such a class that makes it possible. An end user can simply type in any string
they want to search for and use arrow keys to navigate to next or previous occurrence. We
implement ListSearchable, ComboBoxSearchable, TableSearchable, TreeSearchable,
TextComponentSearchable to make JList, JComboBox, JTable, JTree, and JTextComponent
searchable respectively. In addition, we create SearchableUtils encapsulate different classes into
one utility class.
It is very easy to use those classes. For example, if you have a JList, all you need to do is:
The same type of implementation is used to make JTable or JTree searchable – just replace
ListSearchable with the corresponding ComboBoxSearchable, TableSearchable, TreeSearchable
or TextComponentSearchable.
If you need to further configure the searchable, for example make your search criteria case
sensitive, you could do the following:
Usually you do not need to uninstall the searchable from the component. But if for some
reason, you need to disable the searchable feature of the component, you can call
uninstallSearchable():
6 The idea for the searchable feature really came from IntelliJ IDEA. In IDEA, all the trees and lists are searchable. We
found this feature to be very useful and consider it as one of the key features to improve the usability of a user
interface. As a result, we further extended this idea and make JTable searchable too. We also added several more
features such as multiple select and select all that IDEA does not have.
51
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Figure 11 Searchable JList – use up/down arrow key to navigate to next or previous occurrence
For JComboBox, we can only make non-editable combo box searchable. So make sure you
call [Link](false) before you pass it into SearchableUtils7.
For JTextComponent, the searchable popup will not be displayed unless user types in Ctrl-F.
The reason is obvious – because the JTextComponent is usually editable. If the JTextComponent
is not editable, typing any key will show the popup just like other components.
Features
The main purpose of searchable is to make the searching for a particular string easier in a
component having a lot of information. All features are related to how to make it quicker and
easier to identify the matching text.
Navigation feature - After user types in a text and presses the up or down arrow keys, only
items that match with the typed text will be selected. User can press the up and down keys to
7You may wonder why we only support searchable on non-editable combo box. The “searchable” feature on editable
combo box is called auto-completion.
52
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
quickly look at what those items are. In addition, end users can use the home key in order to
navigate to the first occurrence. Likewise, the end key will navigate to the last occurrence. The
navigation keys are fully customizable. The next section will explain how to customize them.
Multiple selection feature - If you press and hold CTRL key while pressing up and down
arrow, it will find next/previous occurrence while keeping existing selections. See the screenshot
below. This way one can easily find several occurrences and apply an action to all of them later.
Select all feature – Further extending the multiple selections feature, you can even select
all. If you type in a searching text and press CTRL+A, all the occurrences matching the searching
text will be selected. This is a very handy feature. For example, you want to delete all rows in a
table whose “name” column begins with “old”. You can type in “old” and press CTRL+A, now all
rows beginning with “old” will be selected. If you hook up delete key with the table, pressing
delete key will delete all selected rows. Imagine without this searchable feature, users will have
to hold CTRL key, look through each row, and click on the row they want to delete. In case they
forgot to hold tight the CTRL key while clicking, they have to start over again.
Basic regular expression support - It allows '?' to match any character and '*' to match any
number of characters. For example “a*c” will match “ac”, “abc”, “abbbc”, or even “a b c” etc.
“a?c” will only match “abc” or “a c”.
Recursive search (only in TreeSearchable) – In the case of TreeSearchable, there is an option
called recursive. You can call TreeSearchable#setRecursive(true/false) to change it. If
TreeSearchable is recursive, it will search all tree nodes including those, which are not visible to
find the matching node. Obviously, if your tree has unlimited number of tree nodes or a
potential huge number of tree nodes (such as a tree to represent file system), the recursive
attribute should be false. To avoid this potential problem in this case, we default it to false.
53
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
The keys used by this class are fully customizable. The subclass can override the methods to
customize the keys. For example, isActivateKey() is defined as below.
In your case, you might need additional characters such as ‘_’, ‘+’ etc. So you can override
the isActivateKey() method to provide additional keys to activate the search pop up. In order to
override a method, you cannot use SearchableUtils anymore. You have to do create a
Searchable yourself. However, it is still very easy. See below.
The other methods (belonging to abstract Searchable) that a subclass can override are
isDeactivateKey(), isFindFirstKey(), isFindLastKey(), isFindNextKey(), isFindPreviousKey()
54
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Resizable Components
In Swing, almost all lightweight components are not resizable8. Heavyweight components,
such as JWindow and the undecorated JDialog, are not resizable either. The main reason for this
is that the component size is determined by layout managers in Swing. If the parent container
size changes, the component size will change accordingly. However, this does not mean there is
no need for resizable components. A typical usage of a resizable panel is in icon or form
designer. See the picture below for an example. While designing the icon, you want to control
the icon size as well. You can do it by resizing the canvas. In this case, the icon size will be the
canvas size.
In addition, to the canvas case above, we also find the need for resizable JWindow or
resizable undecorated JDialog. A typical use case for a resizable window is the combo box. In
Swing’s JComboBox, the pop up is not resizable. However, you can see a resizable popup in IE
(see Figure 5 below). The only way to implement this in Swing is to put the JList in a resizable
JWindow. As a result, we do need a resizable JWindow.
55
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Resizable
The Resizable class is used to ensure that visual component “resizablility” is possible. Very
similar to the Searchable class, Resizable also adds necessary mouse listener capability to a
particular component and makes it resizable when you pass that component to Resizable’s
constructor. You also need to make sure the component has a non-empty border. Otherwise,
there is no place for the mouse cursor to change shape and perform the dragging during
resizing.
The Resizable class supports several options:
ResizableCorners - The value of ResizableCorners is a bitwise OR of eight constants defined
in Resizable This allows end users complete control of which sides/corners are resizable.
ResizeCornerSize – As you know, the mouse cursor will change shape along the resizable
component border. If the mouse is near the corner, it will resize both adjacent sides. The value
of resizeCornerSize will define how big the corner is. The value is in pixel.
beginResizing(), resizing(), and endResizing() – These three methods will be called during
resizing. The beginResizing() and endResizing() methods will be called only once when it starts to
resize and when resizing ends respectively. The resizing() method is called many times during
resizing. By default, resizing() method will set the preferred size of the component and cause the
parent to invoke the doLayout() method. However, it still depends on the parent, a simple
doLayout() may not resize the component correctly. For example, if the parent is JWindow, a top
level container, doLayout() will do nothing. In this case, you should subclass Resizable and
override resizing() method to do something else. For example, in the case of JWindow, you just
need to call setBounds() to change the size and location of JWindow.
56
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
57
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Popup
The intention of developing the JidePopup9 component is to address the common features
of any types of popup. Popup is something that appears above any other windows. However, it
is transient; meaning that when you click outside the popup, the popup is gone. There are many
examples of popup, such as tool tips, combo box popup, and popup menu. If further expanding
the popup concept, there are even more examples, such as new email alert, the famous IntelliJ
IDEA Ctrl-N popup10.
Except the common feature of popup, each popup might have its own characters. For
example, some could be resizable such as the combo box popup (there is an example in
Resizable components section). Some could be movable. Some support time out – it will hide
automatically after several seconds for example. Some are always attached to the invoking
component, such as the combo box. Some are standalone such as email alert. Others might be
attached to the invoking component at the beginning but can be detached by dragging, such as
color split button you can see in MSOffice product. There is also a special category of popups
that support animation when entrancing and exiting – either using fade effect, or flying in/out
effect or using whatever animation effect you can think of. The JidePopup is trying to capture all
those different requirements and provide one solution for you.
JidePopup extends JComponent. You just used it as using any other JComponent by adding
child components to it. JidePopup also supports RootPane which means you can also set a menu
bar on it or use JLayeredPane or GlassPane. The only thing is you don’t want to do is to add
JidePopup to a container. To show it, you just call one of the showPopup() method. See below
for an example. It will create a popup with an empty text area and a sample menu bar, then it
will display the popup.
9 We named JidePopup just to avoid the name conflict with Swing’s Popup, although these two are not quite related.
10 You will understand what this means only if you use IntelliJ IDEA. For those who don’t use IntelliJ IDEA, here is a
short explanation. Ctrl-N in IDEA is hotkey for “Go to Class” where a “dialog” will popup. You can type in part of the
class name and it will list all matches with that name so that you can quickly pick it and go to the class you want to go.
This is probably the most used hotkey in the whole IntelliJ IDEA. When I said “dialog”, it’s not really a dialog although
it looks like one. The difference from dialog is that it doesn’t block. When mouse clicks anywhere outside, the “dialog”
is gone. This is exactly the “unstable” behavior of a popup. By the way, Alt-F1 is another popup example.
58
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
[Link](attachedButton);
[Link](true);
[Link](true);
[Link](view);
[Link]();
Options
Owner: The owner or the invoker of this popup. If you show a popup in the actionPerformed
of a button, the button should be the owner of this popup. If the popup is for a combo box, the
combo box should be the owner. There are several reasons we need this owner. In attached
mode, the owner is the component that popup attaches to. When you call showPopup() without
any parameter, it will place the popup just below the owner.
Resizable: Resizable option is on by default. Depending on the detached/attached mode,
the resizing behavior may be different. If a popup is detached to a component, it only allows you
to resize from bottom, bottom right and right. It obviously doesn’t make sense to resize from
top and top side is aligned with the attached component.
Movable: If a popup is movable, it will show a gripper so that user can grab it and move the
popup. If the popup is attached to its owner, moving it will detach from the owner first.
Detached: Detached is a flag to indicate if the popup is detached from owner or not. You
shouldn’t need to call setDetached() directly. If you call showPopup(), the detached will be true.
DefaultFocusComponent: DefaultFocusComponent is a component on popup. It will receive
keyboard focus when popup is shown.
Timeout: JidePopup can hide itself after certain time. This can be controlled by
setTimeOut(). You can pass in a value, which is taken in millisecond format. If you don't want the
popup to hide after the time out, set the value to 0. By default it's 0 , which means it will never
time out.
59
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
IntelliHints
IntelliHints is a new name we invented to capture a collection of new features we
introduced in the 1.8.3 release. Similar features (in other developer related tools) are called
“code completion” or “intelli-sense” in the context of a text editor or IDE. Without getting into
too much detail, we encourage you to run the B14 example to see different flavors of
IntelliHints. IntelliHints is designed to be extensible. You can easily extend one of existing base
IntelliHints classes such as AbstractIntelliHints or AbstractListIntelliHints or even implement
IntelliHints directly to create your own IntelliHints.
See below for the class hierarchy of IntelliHints related class.
The base IntelliHints is an interface. It has four very basic methods about hints.
/**
* Creates the component which contains hints. At this moment, the content should be empty. Following
call
* {@link #updateHints(Object)} will update the content.
*
* @return the component which will be used to display the hints.
*/
JComponent createHintsComponent();
/**
* Update hints depending on the context.
*
* @param context the current context
* @return true or false. If it is false, hint popup will not be shown.
*/
boolean updateHints(Object context);
/**
* Gets the selected value. This value will be used to complete the text component.
*
* @return the selected value.
*/
Object getSelectedHint();
/**
* Accepts the selected hint.
*
* @param hint
*/
void acceptHint(Object hint);
60
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
components the popup contains. Since in most cases, the hints can be represented by a JList,
here comes the AbstractListIntelliHints. This class assumes JList is used to display hints in the
popup and implements most of the methods in IntelliHints except updateHints() methods.
That’s why it is still abstract. Whatever classes that extend AbstractListIntelliHints should
implement updateHints() method and set the list data to the JList.
There are two concrete implementations included in the current release: FileIntelliHints and
ListDataIntelliHints. FileIntelliHints provides hints based on a file system. ListDataIntelliHints
provides the hints based on a known list. Take a look at the following figures below… The first
one is FileIntelliHints. The list contains the files and folders that match what user typed in so far.
Figure 17 FileIntelliHints
61
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Figure 18 ListDataIntelliHints
Like previously mentioned, IntelliHints can easily be extended. If you can use a JList to
represent the hints, you can extend AbstractListIntelliHints. For example, if you want to
implement code completion as in any IDE like below, AbstractListIntelliHints should be good
enough for you. Like to do what’s in the screenshot below, all you need to do is to override
createList() method in AbstractListIntelliHints and set a special list cell renderer.
If your hints are more complex and cannot be represented by a JList, you will have to extend
AbstractIntelliHints and create your own content for the popup.
IntelliHints is very useful usability feature. If you use it at the right places, it will increase the
usability of your application significantly. Just imagine how dependent you are on the code-
completion feature provided by your Java IDE, why not provide a similar feature to your end
users as well? They will appreciate it. With the help of IntelliHints, it's not far away.
62
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
AutoCompletion
AutoCompletion is a helper class to make JTextComponent or JComboBox auto-complete
based on a list of known items.
There are three constructors. The simplest one is AutoCompletion(JComboBox). It takes any
combobox and make it auto completion. If you are looking for an auto-complete combobox
solution, this is all you need. However AutoCompletion can do more than that. There are two
more constructors. One is AutoCompletion(JTextComponent, Searchable). It will use Searchable
which is another component available in JIDE to make the JTextCompoent auto-complete. We
used Searchable here because it provides a common interface to access the element in JTree,
JList or JTable. In the other word, the known list item we used to auto-complete can be got from
JTree or JList or even JTable or any other component as long as it has Searchable interface
implemented. The last constructor takes any [Link] and use it as auto completion list.
AutoCompletion has a couple options
setStrict(boolean). Sets the strict property. If true, it will not allow user to type in
anything that is not in the known item list. If false, user can type in whatever he/she
wants. If the text can match with a item in the known item list, it will still auto-complete.
setStrictCompletion(boolean). If true, in case insensitive searching, it will always use the
exact item in the Searchable to replace whatever user types. For example, when
Searchable has an item "Arial" and user types in "AR", if this flag is true, it will auto-
completed as "Arial". If false, it will be auto-completed as "ARial". Of course, this flag
will only make a difference if Searchable is case insensitive.
Demos
Overlayable
The overlayable feature provides a way to put a component on top of another component.
A typical usage is to display a small "x" icon on the corner of the component to indicate a
validation error. However, the overlayable feature is much more useful than this.
Here is a screenshot of overlay component on several Swing controls.
63
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
The overlay is a real component, not just a painted image. It supports tooltip, mouse listener
etc just like a regular component. This is very important, as developer always want to associate
an action with the overlay component.
To make it easy for you, we included the following icons as part of the package. You just
need to call [Link](FULL_CONSTANT_NAME) to get the icon.
Here is a way to provide a description to a JTextArea (or JTable, JTree etc) using Overlayable.
The label “Enter description here” is an overlay component. You can control when to show and
hide the overlay component. In this example, when the JTextArea gains focus, we will hide the
overlay component.
Here is one more way to use this feature. See screenshot below, we put a progress spin
(marked with the red arrow) over a JTextArea (picture on the left). You can add a real
JProgressBar as the overlay component (picture on the right).
64
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
The top one shows what it looks like. The icon seems like part of the radio button but it is
not. As you can see from the bottom screenshot, the green rectangle is the boundary of the
radio button. The red rectangle (plus the green rectangle as the green paints over the red) is the
boundary of the overlayable panel. The icon is on the bottom right corner of the overlayable
panel, not the radio button.
If you want to add an icon as overlay component, we need to create a label first.
Next, we need to wrap the radio button to a DefaultOverlayable. We also need to override a
method in radio button to repaint the overlay component correctly. The code will be like below.
65
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
}
}, info, DefaultOverlayable.SOUTH_EAST));
Alternatively, if you use one of the pre-build radio buttons, you can save the overridden
method. OverlayRadioButton is nothing but a JRadioButton that overrides the repaint method as
shown above.
The code is still more complex than the original code. Nevertheless, considering the
powerful feature it added, it is worth the added complexity.
66
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
3. The overlay component is a real component, not just a painted image so that user can
add mouse listener to it or set tooltip etc.
4. Can be placed beyond the component boundary
5. Handle scroll pane well11
6. Support any LookAndFeels without extra code.
7. Can add overlay component to any component
8. Can use any component as the overlay component
We knew many different ways12 to implement this feature. However, after we look at the
criteria above, we ruled out many of the alternatives. JLayeredPane/GlassPane is ruled out
because of bullet 5. Overriding paint method approach is ruled out because of bullet 3 and 4.
Extending or multiplex L&F approach is ruled out because of bullet 6 and 7. Finally, we come up
with this design. I want to point out, although it satisfies almost all the criteria, it is still not
perfect especially we still have to override repaint method. One way to solve it is to provide our
own RepaintManager but it will probably make API harder to understand. If Swing provided a
hook into RepaintManager, it would be perfect. In conclusion, if we would give a rating to this
design from 1 to 5 with 5 being the best, we would give 5 for bullet 3 to bullet 8 and give 3 to
bullet 1 and 2. There is still room for improvement in these two bullets.
11The screenshot below shows how it should behave inside a scroll pane. If you use using JLayerPane, you will see the
error icon is painted above the scroll bar, which is wrong.
12It is worth reading the blog of Kirill Grouchnikov at [Link] He has a series of blogs
on how to support validation overlay.
67
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Image [Link](Image i)
Image [Link](Image i)
Image [Link](Image i, Color color, Insets insets)
See below for the effect of above methods.
IconsFactory
In Java/Swing, you can load an image file as a disk file or as a resource. We found that it’s
easier and faster to load image files as resources. This class is designed to encourage the use of
images and icons as resources.
The IconsFactory acts as a cache manager for ImageIcons and has three static methods:
Each time you call the method, the icon that is returned will be kept in a cache.
Creating overlay icon is a feature of IconsFactory. Imaging you have a “File” icon and a
“New” icon, you want to create a create-a-new-file icon. Of course, you can use Photoshop to
create one. But to make it easy to create those kinds of compound icons on the fly, it’d better
you can use getOverlayIcon(…) method at IconsFactory.
68
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
Another useful method is getIcon(…) method, which takes a portion of a large icon to create
small icons. You can use this method to split a larger into several small icons.
In addition, to the points mentioned above, IconsFactory also has a special usage:
applications typically use hundreds of icons and images. Management of these objects can
easily get out of control. In addition, you might have issues such as duplicate icons, inconsistent
use of icons, difficulty in locating the right icon etc. However with the help of IconsFactory,
these issues become much less of a problem.
In the release, there is a class called VsnetIconsFactory.java13, which looks like this:
…….
If you follow this pattern to create your own Icons Factory, you will get two benefits:
The first is the handy display you see below. Looking at the listing of
VsnetIconsFactory above, notice that there is a ‘main’ method. Run it and an html
file will be generated in the current directory, as shown in the example below. It
will have a list of all icons in the factory, organized into different sections as a table.
In the table, you can see what the icons look like, what the actual image file names
are, and how to use them in the code. Developers should never get lost!
13VsnetIconsFactory is just for tutorial purpose to teach you how to create an IconsFactory. Please do not use any
icons from VsnetIconsFactory in your applications because they are copyrighted by Microsoft.
69
COPYRIGHT © 2002-2012 JIDE SOFTWARE. ALL RIGHTS RESERVED
…….
The second benefit is that with the help of IntelliSense in most Java IDEs, you can
easily locate an icon right in your editor. See overleaf for a screenshot from IntelliJ
IDEA when using IconsFactory.
Internationalization Support
All of the Strings used in JIDE Common Layer are contained in properties files
Note that we have not done any localization: if you want to support languages other
than English, just extract the properties file, translate it to the language you want, add the
correct language postfix and then jar it back into the jide jars. You are welcome to send the
translated properties file back to us if you want to share it!
70
Using JCheckBox as a cell renderer in CheckBoxList and CheckBoxTree primarily enhances user interaction by providing a clear visual indication of selection states, which is more intuitive than highlighting or text-based indicators. This approach allows for easy checking and unchecking of multiple items directly through the checkbox, facilitating more precise and efficient selection management in lists and trees. The checkbox interface aligns with user expectations for item selection and can support additional features like 'dig-in' mode in trees for hierarchical selections .
The dig-in mode in CheckBoxTree allows for a more intuitive selection process by automatically selecting all children nodes when a parent node is checked. This simulates the behavior of recursive selection in hierarchical structures, simplifying the user's task when they wish to select multiple related items. In contrast, the standard tree selection model requires each node to be selected individually, which can be cumbersome for large trees. Dig-in mode consequently streamlines operations, especially in complex selection scenarios, by reducing the need for repetitive actions .
IntelliHints enhance application usability by providing context-sensitive suggestions as the user types, reducing typing errors and accelerating data entry. By filtering and displaying matched items from a list based on user input, IntelliHints enables quicker access to frequently used commands or data. For example, in a file selection dialog, FileIntelliHints can instantly display possible file choices as the user types, facilitating efficient navigation without requiring full path input .
ResizableDialog is particularly effective in scenarios where a customizable, borderless dialog box is required. While standard JDialog is inherently resizable, it loses this property when undecorated. ResizableDialog overcomes this limitation by allowing undecorated dialogs to remain resizable, providing developers with greater flexibility in UI design. This expands the dialog's aesthetic and functional possibilities without sacrificing usability, crucial for applications where presentation and dynamic content accommodation are key .
StyledLabel provides an optimized solution for rendering styled text with different font styles, colors, and line decorations. Unlike JTextPane, StyledLabel is less resource-intensive, making it more suitable for use cases like cell renderers in JList, JTable, or JTree where performance is crucial. It supports subscript, superscript, line decorations, and annotation through StyledLabelBuilder. StyledLabel is also simpler to use in these contexts due to its straightforward style management based on StyleRange, compared to the more complex and heavyweight JTextPane .
A MarqueePane would be more advantageous than a SimpleScrollPane in scenarios where continuous or periodic movement of textual content is required to grab user attention or to display messages in a ticker format. This includes applications like stock tickers, news banners, or any situation where dynamic scrolling of content can help convey information more effectively. Unlike SimpleScrollPane, which uses a button-driven manual scroll method, MarqueePane can provide automated scrolling effects along with pausing to read content, which is beneficial for visually informative displays .
ResizableWindow addresses the inherent limitation of the non-resizable JWindow by adding resizability features, essential for applications requiring dynamic window scaling without title bars. This is crucial in enterprise applications where window content may adjust based on display parameters or user actions. An example utilization of ResizableWindow could be in a complex docking framework where floating windows need to expand or contract based on user interaction or data content, enhancing the flexibility and user experience in professional software suites .
AutoCompletion in JComboBox improves user interface efficiency by enabling predictive text input based on a predefined list of possible selections. This helps users quickly find and select items in the combo box by typing part of the item name, reducing keystrokes and search time. For example, in a form with a country selection dropdown, AutoCompletion allows users to type the initial characters of a country's name to instantly narrow down the list, facilitating quicker and more accurate selections .
The Overlayable feature enhances GUI components by allowing additional visual elements to be layered over existing components without altering the underlying functionality. This feature can be used to display validation icons, progress indicators, or error messages adjacent to a text field or any other component, improving interactive feedback. It enables developers to attach tooltips, mouse listeners, and actions to overlays, which can improve user interaction and error management. By adding overlays to a dedicated overlayable panel, developers maintain component modularity while enhancing functionality .
StyledLabel, when combined with StyleRange, outperforms standard JLabel in applications that demand rich text formatting features with dynamic style changes, such as in data visualization, document viewers, or educational software where textual emphasis is required. The ability to apply varying fonts, colors, and effects like superscript or underline within a single text component allows for the creation of visually distinct and appealing UIs. StyleRange provides granular control over text appearance, enabling developers to highlight or differentiate sections of text efficiently, which standard JLabel cannot achieve without extensive customization .