Adding Separators to Your Toolbar

Separators enable you to group toolbar buttons into functional areas. If you look at the toolbar you created and executed in Figure 4-1, you will see that there are a couple of functional areas. The first is the Open and Save functionality. The second is the Cut, Copy, and Paste functionality. As it now appears, nothing distinguishes the two functional areas from each other as the user gazes at the toolbar. To provide that visual distinction, you must add a separator.

How do I do that?

Separators are easy to create:

final ToolItem separator = new ToolItem(bar, SWT.SEPARATOR);

If you insert this line of code in the location where you wish the separator to appear (between the code that creates the Save button and the code that creates the Cut button), the toolbar appears as in Figure 4-3—a distinct improvement.

Toolbar with separator

Figure 4-3. Toolbar with separator

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.