How to use GWT 2.1 Data Presentation Widgets

后端 未结 6 1688
深忆病人
深忆病人 2020-11-30 19:05

At the 2010 Google IO it was announced that GWT 2.1 would include new Data Presentation Widgets. 2.1M is available for download, and presumably the widgets are included, but

6条回答
  •  情话喂你
    2020-11-30 19:49

    To show multiple column in table you need to put array in list. The reference code to achieve this is:

    package com.test.client;
    
    import java.util.ArrayList;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.cellview.client.CellTable;
    import com.google.gwt.user.cellview.client.SimplePager;
    import com.google.gwt.user.cellview.client.TextColumn;
    import com.google.gwt.user.client.ui.HTML;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.view.client.ListViewAdapter;
    import com.google.gwt.view.client.SingleSelectionModel;
    
    public class Index implements EntryPoint {
    
        public void onModuleLoad() {
    
            // create some data
            ArrayList values = new ArrayList();
            values.add(new String[] { "1", "a" });
            values.add(new String[] { "2", "b" });
            values.add(new String[] { "3", "c" });
            values.add(new String[] { "4", "d" });
            values.add(new String[] { "5", "e" });
            values.add(new String[] { "6", "f" });
            values.add(new String[] { "7", "g" });
            values.add(new String[] { "8", "h" });
            values.add(new String[] { "9", "i" });
            values.add(new String[] { "10", "j" });
    
    
            // create a ListViewAdapter
            ListViewAdapter lva = new ListViewAdapter();
            // give the ListViewAdapter our data
            lva.setList(values);
    
            RootPanel.get().add(new HTML("
    ")); { // CellTable CellTable ct = new CellTable(); ct.setSelectionEnabled(true); ct.setSelectionModel(new SingleSelectionModel()); ct.setPageSize(2); lva.addView(ct); ct.addColumn(new TextColumn() { @Override public String getValue(String[] object) { return object[0]; } }, "First"); ct.addColumn(new TextColumn() { @Override public String getValue(String[] object) { return "%" + object[1] + "%"; } }, "Second"); // create a pager, giving it a handle to the CellTable SimplePager pager = new SimplePager(ct, SimplePager.TextLocation.CENTER); // add the Pager to the page RootPanel.get().add(pager); // add the CellList to the page RootPanel.get().add(ct); } } }

提交回复
热议问题