DekGenius.com
Previous Section  < Day Day Up >  Next Section

Recipe 9.6 Embedding Combo Boxes, Text Widgets, and Menus in Toolbars

9.6.1 Problem

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.

9.6.2 Solution

Toolbars can act as widget containers for widgets such as combo boxes. And you can make menus open from inside a toolbar.

9.6.3 Discussion

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).

    Previous Section  < Day Day Up >  Next Section