Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2011-10-28 16:20:03 +0000
committerBogdan Gheorghe2011-10-28 16:20:03 +0000
commit2127a4c369a33dc2d3b5bead0c7e1427297d5bd4 (patch)
treeda275dc36e21536a30957f23f89ad1f423609fba
parent270369a2774c9adb72d20072ee39a162882a5dda (diff)
downloadeclipse.platform.swt-2127a4c369a33dc2d3b5bead0c7e1427297d5bd4.tar.gz
eclipse.platform.swt-2127a4c369a33dc2d3b5bead0c7e1427297d5bd4.tar.xz
eclipse.platform.swt-2127a4c369a33dc2d3b5bead0c7e1427297d5bd4.zip
Add Snippet 359
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet359.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet359.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet359.java
new file mode 100644
index 0000000000..10b289df9d
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet359.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This Example Content is intended to demonstrate
+ * usage of Eclipse technology. It is provided to you under the terms and
+ * conditions of the Eclipse Distribution License v1.0 which is available
+ * at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+
+/*
+ * Combo getCaretLocation and getCaretPosition example
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class Snippet359 {
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ final Combo combo = new Combo(shell, SWT.DROP_DOWN);
+ combo.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e) {
+ if (e.keyCode == SWT.CR) {
+ combo.add(combo.getText());
+ }
+ }
+ public void keyPressed(KeyEvent e) {
+ System.out.println("caret position: " + combo.getCaretPosition());
+ System.out.println("caret location: " + combo.getCaretLocation());
+ }
+ });
+ shell.pack();
+ shell.open ();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+ display.dispose ();
+ }
+}

Back to the top