Chapter 15. SWT CoolBars

Chapter 4 demonstrated the creation and use of SWT ToolBars. This chapter examines another set of classes that can be used to create ToolBar-like constructs—the SWT CoolBar and CoolItem classes from the org.eclipse.swt.widgets package.

A CoolBar is like a ToolBar on steroids. Like ToolBar and ToolItems, CoolBar is a container to which you add instances of the CoolItem class.Although a ToolItem object appears as a button on the ToolBar, a CoolItem serves only as a container for other widget types—Combo, Text, or Button. This makes a CoolBar a massively useful interface construct. In fact, the Eclipse toolbar is actually a CoolBar and is a great example of how to leverage the capability of the CoolBar and CoolItem classes to enable the user to customize the user interface.

Creating a CoolBar

The steps required to create a CoolBar are similar to those required to create a ToolBar, except that an instance of CoolBar is created instead of ToolBar and instances of CoolItem are created in place of the ToolItem instances for the individual buttons. The similarity ends there, however.

The CoolItem objects created serve only as containers for other widgets. If you want to create a CoolBar similar in appearance to the ToolBar from Chapter 4, you must create individual Button objects that are added to the corresponding CoolItem. A good understanding of CoolBar can be gained by going through the process of creating a CoolBar similar in appearance to the ToolBar created ...

Get SWT: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.