diff options
author | Carolyn MacLeod <carolyn> | 2008-04-02 05:02:52 +0000 |
---|---|---|
committer | Carolyn MacLeod <carolyn> | 2008-04-02 05:02:52 +0000 |
commit | f18e9dda2b54542a6afc8eb341f631aa41a0ddf7 (patch) | |
tree | e9d23cb05bab43dba7fac9ede8a23fc4e43adb6d /examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java | |
parent | e60a3ad64bf035f641febfe15e4f9e47e3913f05 (diff) | |
download | eclipse.platform.swt-f18e9dda2b54542a6afc8eb341f631aa41a0ddf7.tar.gz eclipse.platform.swt-f18e9dda2b54542a6afc8eb341f631aa41a0ddf7.tar.xz eclipse.platform.swt-f18e9dda2b54542a6afc8eb341f631aa41a0ddf7.zip |
bug 224642
Diffstat (limited to 'examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java')
-rw-r--r-- | examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java index b30d8a14ed..e4c6dab7e5 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java @@ -19,6 +19,7 @@ package org.eclipse.swt.snippets; import org.eclipse.swt.*; import org.eclipse.swt.custom.*; import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; public class Snippet296 { @@ -54,6 +55,25 @@ public static void main (String[] args) { tree.setSize (clientWidth, prefHeight); } }); + /* + * The following listener ensures that a newly-selected item + * in the Tree is always visible. + */ + tree.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + TreeItem [] selectedItems = tree.getSelection(); + if (selectedItems.length > 0) { + Rectangle itemRect = selectedItems[0].getBounds(); + Rectangle area = sc.getClientArea(); + Point origin = sc.getOrigin(); + if (itemRect.x < origin.x || itemRect.y < origin.y + || itemRect.x + itemRect.width > origin.x + area.width + || itemRect.y + itemRect.height > origin.y + area.height) { + sc.setOrigin(itemRect.x, itemRect.y); + } + } + } + }); Button downButton = new Button (shell, SWT.PUSH); downButton.setBounds (10, 220, 120, 30); |