[sample] tableview + arrayContentProvide + default labelProvide + IFontProvider

[sample] tableview + arrayContentProvide + default labelProvide + IFontProvider

public class TableViewer6 {
    public static void creatShellArae(Shell shell) {
        Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
        table.setHeaderVisible(true);
        for(int i=0; i < 3; i++) {
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setText("column " + i); column.setWidth(100);
        }

        TableViewer viewer = new TableViewer(table);
        viewer.setContentProvider(new ArrayContentProvider());
        viewer.setLabelProvider(new myLableProvider2());

        String[] input = {"a","b","c"};
        viewer.setInput(input);
    }

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

        creatShellArae(shell);

        shell.open();
        shell.layout();

        while (!shell.isDisposed())
            if (!display.readAndDispatch())
                display.sleep();

    }
}
class myLableProvider2 extends LabelProvider implements IFontProvider {
    public Font getFont(Object element) {
        if(element.toString().equals("a"))
            return JFaceResources.getDefaultFont();
        else
            return JFaceResources.getBannerFont();
    }
}

 

你可能感兴趣的:(tableview)