1 package org.eclipse.swt.tests.gtk.snippets;
2 /*******************************************************************************
3  * Copyright (c) 2000, 2018 IBM Corporation and others.
4  *
5  * This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License 2.0
7  * which accompanies this distribution, and is available at
8  * https://www.eclipse.org/legal/epl-2.0/
9  *
10  * SPDX-License-Identifier: EPL-2.0
11  *
12  * Contributors:
13  *     IBM Corporation - initial API and implementation
14  *******************************************************************************/
15 
16 
17 /*
18  * List example snippet: print selected items in a widget.list
19  *
20  * For a widget.list of all SWT example snippets see
21  * http://www.eclipse.org/swt/snippets/
22  */
23 import org.eclipse.swt.*;
24 import org.eclipse.swt.graphics.*;
25 import org.eclipse.swt.widgets.*;
26 
27 public class Bug495909_topItemTree {
28 
main(String [] args)29 public static void main (String [] args) {
30 	Display display = new Display ();
31 	Shell shell = new Shell (display);
32 	final Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
33 	for (int i=0; i<128; i++) new TreeItem (tree, 0).setText("Item " + i);
34 	tree.setTopItem(tree.getItem(40));
35 	System.out.println(tree.getTopItem().getText());
36 	Rectangle clientArea = shell.getClientArea ();
37 	tree.setBounds (clientArea.x, clientArea.y, 100, 100);
38 	tree.addListener (SWT.MouseWheel, e -> {
39 		System.out.println(tree.getTopItem().getText());
40 	});
41 	tree.addListener (SWT.Selection, e -> {
42 		System.out.println(tree.getTopItem().getText());
43 	});
44 	tree.setTopItem(tree.getItem(20));
45 	System.out.println(tree.getTopItem().getText());
46 	shell.pack ();
47 	shell.open ();
48 	while (!shell.isDisposed ()) {
49 		if (!display.readAndDispatch ()) display.sleep ();
50 	}
51 	display.dispose ();
52 }
53 }
54