Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: abcb60227cdd3bf4b0424297a9da0d7b7a679fc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
 * Copyright (c) 2018 Red Hat and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tests.gtk.snippets;


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class Bug465054_PaintItemTestSnippet {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shellMain = new Shell(display, SWT.SHELL_TRIM);
		shellMain.setLayout(new FillLayout(SWT.VERTICAL));

		Tree tree = new Tree(shellMain, SWT.BORDER);
		new TreeItem(tree, SWT.NONE).setText("setText");
		for (int i = 0; i < 100; i++) {
			new TreeItem(tree, SWT.NONE).setText("setText " + i);
		}

		tree.addListener(SWT.PaintItem, new Listener() {
			@Override
			public void handleEvent(Event event) {
				System.out.println("PaintItem");
				Rectangle bounds = ((TreeItem) event.item).getBounds(event.index);
				event.gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
				event.gc.drawText(((TreeItem) event.item).getText(), bounds.x, bounds.y, true);
			}
		});
		

		shellMain.open();

		while (!shellMain.isDisposed()) {
			try {
				if (!display.readAndDispatch())
					display.sleep();
			} catch (Throwable t) {
				t.printStackTrace();
			}
		}
		display.dispose();
	}
}

Back to the top