Create a multiple-selection list : List « SWT « Java Tutorial






Create a multiple-selection list
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;

public class CreateMultipleSelectionList {
  // Strings to use as list items
  private static final String[] ITEMS = { "A", "B", "C", "D" };

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    // Create a multiple-selection list
    List multi = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);


    // Add the items, one by one
    for (int i = 0, n = ITEMS.length; i < n; i++) {
      multi.add(ITEMS[i]);
    }

    
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}








17.23.List
17.23.1.Introducing List and List Styles
17.23.2.Create a single-selection list and add itemsCreate a single-selection list and add items
17.23.3.List Item Single SelectionList Item Single Selection
17.23.4.Create a multiple-selection listCreate a multiple-selection list
17.23.5.Create a List with a vertical ScrollBar and Add a bunch of items to itCreate a List with a vertical ScrollBar and Add a bunch of items to it
17.23.6.Setting Items: Add the items all at onceSetting Items: Add the items all at once
17.23.7.Make List Scroll to the bottomMake List Scroll to the bottom
17.23.8.Show the selection value by using ScrollBarShow the selection value by using ScrollBar
17.23.9.Select a rangeSelect a range
17.23.10.Copying Lists: public static void copy(List dest, List src)
17.23.11.Multiple-Copy Collections
17.23.12.Reversing Lists: public static void reverse(List list)
17.23.13.public static void fill(List list, Object element): method copies the same object reference to every element of the list
17.23.14.Shuffling Lists: randomly reorder the elements of a list
17.23.15.Sorting Lists: reordering the elements of a List