Recipe 9.6 Embedding Combo Boxes, Text Widgets, and Menus in Toolbars
For many uses, buttons are fine in toolbars. But if you want to impress users, you can add other widgets such as combo boxes or drop-down menus.
Toolbars can act as widget containers for widgets such as combo boxes. And you can make menus open from inside a toolbar.
When you create most widgets, you specify what container you want to use, and you can add widgets to toolbars by making them widget containers. For example, here's how you can add a text widget to a toolbar:
Text text = new Text(toolbar, SWT.BORDER);
And here's how you can add a combo box widget:
Combo combo = new Combo(toolbar, SWT.READ_ONLY);
Menus are a little more complex. In SWT, however, you support toolbar menus with context menus, setting their location inside a toolbar and making them visible as needed using code such as this:
menu.setLocation(point.x, point.y); menu.setVisible(true);
9.6.4 See Also
Recipe 9.3 on creating toolbars; Recipe 9.4 on embedding buttons in toolbars; Recipe 9.5 on handling toolbar events; Chapter 8 in Eclipse (O'Reilly).