Grid Cell Formatter : Grid « GWT « Java






Grid Cell Formatter



package com.java2s.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollListener;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.RootPanel;

public class GWTClient implements EntryPoint{
  public void onModuleLoad() {
        Grid grid = new Grid(2, 4);
        grid.setWidget(0, 0, new Label("0,0"));
        grid.setWidget(0, 1, new Label("Grid"));
        grid.setWidget(0, 2, new Label("0,2"));
        grid.setWidget(0, 3, new Label("0,3"));
        grid.setWidget(1, 0, new Label("1,0"));
        grid.setWidget(1, 1, new Label("1,1"));
        grid.setWidget(1, 2, new Label("1,2"));
        grid.setWidget(1, 3, new Label("1,3"));
        grid.setStyleName("panel grid");
        for (int i = 0; i < grid.getRowCount(); i++) {
            for (int j = 0; j < grid.getCellCount(i); j++) {
                if ((j % 2) == 0) {
                    grid.getCellFormatter().setStyleName(i, j, "tableCell-even");
                } else {
                    grid.getCellFormatter().setStyleName(i, j, "tableCell-odd");
                }
            }
        }

    RootPanel.get().add(grid);
  }
}
///////////
.grid {
  width: 150px;
  height: 50px;
  padding: 5px;
  position: absolute; 
  left: 220px; 
  top: 350px;  
}


.tableCell-even {
  padding: 5px;
  background: #008AB8;
  border: 1px solid #ffffff;
}

.tableCell-odd {
  padding: 5px;
  background: #FFCC33;
  border: 1px solid #ffffff;
}


.panel {
  background-color: #C3D9FF;
  border: 1px solid #000000;
  padding: 3px;
  margin: 3px;
  font-weight: normal;  
}

           
       








GWT-gridCellFormatter.zip( 3 k)

Related examples in the same category

1.Grid control