Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [nebula-dev] Lazy initialisation of grid

On 8/8/07, Christopher J Gross <chris.gross@xxxxxxxxxx> wrote:

You need to call setItemCount.  Tell the Grid how many items you want.

Regards,

-Chris

Okey so this is how it looks now.

It still don't call handleEvent() and hence all the cells are empty... :(



import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn ;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout ;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class VirtualGridWidget {
    public static void main(String... args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
                     
        Grid grid = new Grid( shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.VIRTUAL | SWT.MULTI );
        grid.setHeaderVisible(true);
        grid.setRowHeaderVisible(true);
        grid.setCellSelectionEnabled(true);
       
        grid.setItemHeight(20);
        grid.setItemCount(10);
        for (int i = 0; i < 10; i++) {
           
            GridColumn column = new GridColumn(grid, SWT.NONE);
            column.setText(i + "");
            column.setWidth(40);
        }
       
        grid.addListener( SWT.SetData, new Listener() {
            public void handleEvent(Event event) {
                System.out.println("handleEvent()");
                GridItem item = (GridItem)event.item;
                for (int i = 0; i < 10; i++) {
                    item.setText(i, i + "");
                    item.setHeaderText( ('a'+i) + "" );
                }
            }
        } );
       
        shell.setSize(500, 200);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

Back to the top