1 package org
.eclipse
.tracecompass
.internal
.provisional
.tmf
.ui
.views
.timegraph2
.swtjfx
.examples
;
3 /*******************************************************************************
4 * Copyright (c) 2000, 2016 IBM Corporation and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM Corporation - initial API and implementation
12 *******************************************************************************/
15 * ToolBar example snippet: place a drop down menu in a tool bar
17 * For a list of all SWT example snippets see
18 * http://www.eclipse.org/swt/snippets/
20 import org
.eclipse
.swt
.*;
21 import org
.eclipse
.swt
.graphics
.*;
22 import org
.eclipse
.swt
.widgets
.*;
24 public class TestSwtToolbar
{
26 public static void main(String
[] args
) {
27 final Display display
= new Display();
28 final Shell shell
= new Shell(display
);
30 final ToolBar toolBar
= new ToolBar(shell
, SWT
.NONE
);
31 Rectangle clientArea
= shell
.getClientArea();
32 toolBar
.setLocation(clientArea
.x
, clientArea
.y
);
34 final Menu menu
= new Menu(shell
, SWT
.POP_UP
);
35 for (int i
= 0; i
< 8; i
++) {
36 MenuItem item
= new MenuItem(menu
, SWT
.PUSH
);
37 item
.setText("Item " + i
);
40 final ToolItem item
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
41 item
.addListener(SWT
.Selection
, event
-> {
42 if (event
.detail
== SWT
.ARROW
) {
43 Rectangle rect
= item
.getBounds();
44 Point pt
= new Point(rect
.x
, rect
.y
+ rect
.height
);
45 pt
= toolBar
.toDisplay(pt
);
46 menu
.setLocation(pt
.x
, pt
.y
);
47 menu
.setVisible(true);
54 while (!shell
.isDisposed()) {
55 if (!display
.readAndDispatch()) {
This page took 0.031334 seconds and 5 git commands to generate.