|
What this is
Other links
The source code/******************************************************************************* * Copyright (c) 2006 Tom Schindl and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Tom Schindl - initial API and implementation *******************************************************************************/ package org.eclipse.jface.snippets.viewers; 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.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** * Demonstrate a simple ListViewer */ public class Snippet039ListViewer { private class MyContentProvider implements IStructuredContentProvider { public Object[] getElements(Object inputElement) { return (MyModel[])inputElement; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } } public class MyModel { public int counter; public MyModel(int counter) { this.counter = counter; } public String toString() { return "Item " + this.counter; } } public Snippet039ListViewer(Shell shell) { final ListViewer v = new ListViewer(shell,SWT.H_SCROLL|SWT.V_SCROLL); v.setLabelProvider(new LabelProvider()); v.setContentProvider(new MyContentProvider()); MyModel[] model = createModel(); v.setInput(model); } private MyModel[] createModel() { MyModel[] elements = new MyModel[10]; for( int i = 0; i < 10; i++ ) { elements[i] = new MyModel(i); } return elements; } /** * @param args */ public static void main(String[] args) { Display display = new Display (); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); new Snippet039ListViewer(shell); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.