summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet296.java20
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);