Results 1 to 1 of 1
-
How to use SWT List Selection Event
Java Code:import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class ListClass { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("List Example"); shell.setSize(300, 200); final List list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); list.setBounds(40, 20, 220, 100); for (int loopIndex = 0; loopIndex < 9; loopIndex++) { list.add("Item Number " + loopIndex); } final Text text = new Text(shell, SWT.BORDER); text.setBounds(60, 130, 160, 25); list.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { int[] selectedItems = list.getSelectionIndices(); String outString = ""; for (int loopIndex = 0; loopIndex < selectedItems.length; loopIndex++) outString += selectedItems[loopIndex] + " "; text.setText("Selected Items: " + outString); } public void widgetDefaultSelected(SelectionEvent event) { int[] selectedItems = list.getSelectionIndices(); String outString = ""; for (int loopIndex = 0; loopIndex < selectedItems.length; loopIndex++) outString += selectedItems[loopIndex] + " "; System.out.println("Selected Items: " + outString); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Dir File Selection
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:58 PM -
Selection sort in Java
By Java Tip in forum AlgorithmsReplies: 0Last Post: 04-15-2008, 07:41 PM -
radiobutton selection
By newtojava7 in forum New To JavaReplies: 1Last Post: 03-17-2008, 02:58 AM -
validating selection list in struts!
By rameshraj in forum Web FrameworksReplies: 2Last Post: 02-13-2008, 01:21 PM -
Code for selection
By kneekow in forum EclipseReplies: 0Last Post: 02-01-2008, 03:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks