Enhancing the Flamingo command button component

June 25th, 2008

Over the course of the past few weeks the command button component in Flamingo component suite has been enhanced following the feedback from the project users. There is nothing better than getting the feedback from real-world use, and it is much appreciated on my side. Many thanks go to Kenneth Flynn and Christian Hebert for finding time to report these issues.

Supporting the disabled state

Calling setEnabled(false) on a command button will display the correct disabled state. As with the core AbstractButton, you can set a disabled icon with setDisabledIcon API. The helper org.jvnet.flamingo.common.icon.FilteredResizableIcon class can be used to wrap an existing resizable icon with a ColorConvertOp based on ColorSpace.CS_GRAY (core JDK functionality). Here is a screenshot of a few command buttons in enabled state:

And here are the same buttons in disabled state. Note how the visuals are changed to reflect the new state (including the foreground color of the main text and the extra text, as well as the popup arrow icon). The buttons in the first column specify a custom disabled icon (with the APIs mentioned above).

Supporting changing the text

Previously, once a command button has been created, it was not possible to change its display text with the setText(String) API. The new version supports this API, tracking the display text and recomputing the strings under the BIG and CUSTOM states as necessary. Here is a screenshot of a few command buttons with the default “Click!” text:

And here are the same buttons after they have been clicked a number of times. Each button has an action listener that counts the number of clicks and updates the button text accordingly. Note how the displayed text and the preferred size of the buttons are changed (automatically):

Supporting changing the font

Previously, the command button would ignore setting a custom font with setFont(Font) API. The new version supports this API. Here is a screenshot of a few command buttons using a custom italic font:

Support auto-repeat action mode

The auto-repeat action mode comes in handy when you want to have the action listeners invoked every N milliseconds as long as the button is pressed. This functionality is present, for example, on the arrow buttons in the core scroll bars. Once the scroll arrow button is pressed, it starts firing the scroll action events every 60 milliseconds after the initial delay of 300 milliseconds.

The JCommandButton component has two new APIs to support the auto-repeat action mode. Use the setAutoRepeatAction(true) to set the auto-repeat action mode on. The default initial delay is 500 milliseconds and the default subsequent delay is 100 milliseconds. To change the default values, call setAutoRepeatActionIntervals(int, int) API.

Support column-fill mode on command button panel

Previously, the command button panel component only supported row-fill mode. Under this mode, the buttons are placed in row-first fashion, wrapping the rows when the panel width is reached. Now, the component also supports the column-fill mode. Use the setLayoutKind(LayoutKind) API to specify the layout mode. Here is a screenshot of a command button panel with the default row-fill mode (note the vertical scroll bar):

and here is the same panel under the column-fill mode (notice the horizontal scroll bar):

This functionality is available in the latest 3.1dev drop of Flamingo.