< Day Day Up > |
Recipe 9.3 Creating Toolbars9.3.1 ProblemYou want to create a toolbar and handle toolbar button clicks. 9.3.2 SolutionUse the SWT Toolbar and ToolItem classes. 9.3.3 DiscussionWe'll create an example toolbar in a new project (ToolbarApp at this book's site) and stock it with toolbar buttons, reporting which button the user clicked. To create a toolbar, you use the SWT Toolbar class; here's a selection of this class's most popular methods:
Here's how you can create a new SWT toolbar: public class ToolbarClass { public static void main(String [] args) { Display display = new Display( ); final Shell shell = new Shell(display); shell.setSize(300, 200); shell.setText("Toolbar Example"); ToolBar toolbar = new ToolBar(shell, SWT.NONE); toolbar.setBounds(0, 0, 200, 70); . . . The next step is to add some buttons to the toolbar; see the following recipe for the details. 9.3.4 See AlsoRecipe 9.4 on embedding buttons in toolbars; Recipe 9.5 on handling toolbar events; Recipe 9.6 on embedding combo boxes, text widgets, and menus in toolbars; Chapter 8 in Eclipse (O'Reilly). |
< Day Day Up > |