Here's code I'd use to create a simplistic chess board:
// the chess board with no spaces
Grid cb = new Grid(10, 10);
cb.setCellPadding(0);
cb.setCellSpacing(0);
cb.setBorderWidth(0);
// assembles the board by inserting colored panels
for (int i = 1; i < 9; i++) {
// panels of the top row
SimplePanel pHTop = new SimplePanel();
pHTop.setPixelSize(40, 20);
pHTop.getElement().getStyle().setBackgroundColor("red");
// panels of the bottom row
SimplePanel pHBottom = new SimplePanel();
pHBottom.setPixelSize(40, 20);
pHBottom.getElement().getStyle().setBackgroundColor("red");
// panels of the left column
SimplePanel pVLeft = new SimplePanel();
pVLeft.setPixelSize(20, 40);
pVLeft.getElement().getStyle().setBackgroundColor("green");
// panels of the right column
SimplePanel pVRight = new SimplePanel();
pVRight.setPixelSize(20, 40);
pVRight.getElement().getStyle().setBackgroundColor("green");
// insert the border cells
cb.setWidget(0, i, pHTop);
cb.setWidget(9, i, pHBottom);
cb.setWidget(i, 0, pVLeft);
cb.setWidget(i, 9, pVRight);
for (int j = 1; j < 9; j++) {
// the inner chess board panels
SimplePanel cP = new SimplePanel();
cP.setPixelSize(40, 40);
// switches between black and white
if (j % 2 == 0) {
cP.getElement().getStyle().setBackgroundColor(
i % 2 == 0 ? "black" : "white");
} else {
cP.getElement().getStyle().setBackgroundColor(
i % 2 == 0 ? "white" : "black");
}
cb.setWidget(i, j, cP);
}
}
// there it is
RootPanel.get().add(cb, 1, 1);
Programmatic styles are of course not as good as using stylesheets,
consider this just a demo.
On 28 Jun., 11:51, andreas <[email protected]> wrote:
> Where exactly are the vertical spaces? From what I see, there are no
> spaces between the cells of the top and bottom row and the spaces
> between the cells in the left and right column are of the same color
> as the image background, so I assume there are actually also no
> spaces, correct me on this one?
>
> For better debug you could also assign a border and background color
> to the Grid. If none of these colors will be visible you can be sure
> that there are no spaces or anything left.
>
> For the inner cells I can not say if there are any spaces.
>
> Also I assume your style "pnl-r" adds the red border to the Grid? If
> there were any spaces left caused by the border width you would see a
> red Grid.
>
> I think you got what you wanted...
>
> BTW: I think you do not need to set the cell dimensions manually; Grid
> will automatically adjust cell dimensions so that the cell widgets
> fit, in other words a columns width for example will be adjusted so
> that the cell widget with the biggest width is completely visible;
> same goes for rows and heights and so on
>
> BTW2: the two for-blocks in init() can be realized in one single for-
> block since they iterate over exactly the same interval (0-9)
>
> On 28 Jun., 11:27, Magnus <[email protected]> wrote:
>
>
>
> > Here is the screenshot:
>
> >http://yfrog.com/j7chessboardj
>
> > Magnus
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.