Make List Scroll to the bottom : List « SWT « Java Tutorial






Make List Scroll to the bottom
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 ListScrollBottom {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());


    // Create a List with a vertical ScrollBar
    List list = new List(shell, SWT.V_SCROLL);

    // Add a bunch of items to it
    for (int i = 0; i < 500; i++) {
      list.add("A list item");
    }

    // Scroll to the bottom
    list.select(list.getItemCount() - 1);
    list.showSelection();

    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