SWT List Composite : List « SWT JFace Eclipse « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » SWT JFace Eclipse » ListScreenshots 
SWT List Composite

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

public class Ch8ListComposite extends Composite {
  public Ch8ListComposite(Composite parent) {
    super(parent, SWT.NULL);
    populateControl();
  }

  protected void populateControl() {
    FillLayout compositeLayout = new FillLayout();
    setLayout(compositeLayout);

    int[] styles = SWT.SINGLE, SWT.MULTI };

    for (int style = 0; style < styles.length; style++) {
      createListViewer(styles[style]);
    }
  }

  private void createListViewer(int style) {
    ListViewer viewer = new ListViewer(this, style);

    viewer.setLabelProvider(new LabelProvider() {
      public String getText(Object element) {
        return ((ListItemelement).name;
      }
    });

    viewer.addFilter(new ViewerFilter() {
      public boolean select(Viewer viewer, Object parent, Object element) {
        return ((ListItemelement).value % == 0;
      }
    });

    viewer.setSorter(new ViewerSorter() {
      public int compare(Viewer viewer, Object obj1, Object obj2) {
        return ((ListItemobj2).value - ((ListItemobj1).value;
      }
    });

    viewer.setContentProvider(new IStructuredContentProvider() {

      public Object[] getElements(Object inputElement) {
        return ((ListinputElement).toArray();
      }

      public void dispose() {
      }

      public void inputChanged(Viewer viewer, Object oldInput,
          Object newInput) {
      }
    });

    List input = new ArrayList();
    for (int i = 0; i < 20; i++) {
      input.add(new ListItem("item " + i, i));
    }

    viewer.setInput(input);
  }

}

class ListItem {
  public String name;

  public int value;

  public ListItem(String n, int v) {
    name = n;
    value = v;
  }
}

           
       
Related examples in the same category
1.List DemoList Demo
2.Single Multi ListsSingle Multi Lists
3.Sample ListSample List
4.Demonstrates ListsDemonstrates Lists
5.List ExampleList Example
6.List Example 2List Example 2
7.List Example 3List Example 3
8.SWT List Example DemoSWT List Example Demo
9.SWT List Selection EventSWT List Selection Event
10.Print selected items in a listPrint selected items in a list
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.