X

Geertjan's Blog

  • August 16, 2010

Pluggable Accordion

Geertjan Wielenga
Product Manager
In exchange for blogging about them, I've been given a free look at the new Java Swing Components. Here's the Accordion component in action within a NetBeans Platform application:

All the components provided by Java Swing Components rely on a formatting rule engine to determine how text is rendered, which is what allows you to mix and match fonts, colors, and other font styles in a single wrapped label, which is one of the other components provided by Java Swing Components. The Accordion's cell renderers make use of the same formatting engine to determine rendering, which allows you to mix and match fonts and formatting rules in the accordion tabs as well:

//Create a new TabRenderer based on the steel UI:
SteelVerticalTabRenderer steelTabRenderer = new SteelVerticalTabRenderer(accordion);
//Hide the index to make the most use of limited space:
steelTabRenderer.setShowIndex(false);
//Apply normal text rules to determine how normal text is rendered:
steelTabRenderer.setNormalTextFormattingRules(
new TextFormattingRuleBuilder().createRule()
.setFontSize(12)
.setFontFamily(getFont().getFamily())
.setForeground(Color.BLACK)
.build()
);
//Apply mouse over text rules to determine how text is displayed when the mouse is over the tab:
steelTabRenderer.setMouseOverTextFormattingRules(
new TextFormattingRuleBuilder().createRule()
.setFontSize(12)
.setFontFamily(getFont().getFamily())
.setWeight(Weight.BOLD)
.build()
);
//Apply selected text rules to determine how text is displayed when the tab is selected:
steelTabRenderer.setSelectedTextFormattingRules(
new TextFormattingRuleBuilder().createRule()
.setFontSize(12)
.setFontFamily(getFont().getFamily())
.setForeground(new Color(70,25,121))
.setWeight(Weight.BOLD)
.build()
);
accordion.setVerticalAccordionTabRenderer(steelTabRenderer);

The above results in the following rendering:

It reminds me a bit of the Eclipse PShelf Widget and the JOutlookBar, which I blogged about here.

In a modular application, each of the tabs could be contributed by a different module, as illustrated in the Pluggable JXTaskPane article. Modularity really enriches a component such as the above, since simple tabs could be provided for free (via free plugins), while more complex tabs could be part of a pricing strategy, which could then be installed (explicitly or silently) once the purchase has been processed.

Each of the components provided by Java Swing Components is accompanied by sample code and by a very clear PDF file that documents the main features of the component in question. In the case of the Accordion component, you can create new tabs, listen to tab changes, change the look and feel, and customize the accordion (background painter, accordion tab renderer, and you can even create a custom accordion UI).

It is a project worth supporting!

Join the discussion

Comments ( 2 )
  • Numpty Monday, August 16, 2010

    Yuck. I've loathed accordion widgets and their dreadful usability since the first day I ever saw one in the Microsoft Exchange client (as Microsoft Outlook was originally called), back in 1995.

    Its introduction caused more support calls in one day (from people who thought they'd lost all their email) than any other system upgrade I can remember.


  • Geertjan Wielenga Monday, August 16, 2010

    1995 is quite a while ago, Numpty. People nowadays have a pretty good idea of what to expect from an accordion component.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.