Monday, June 28, 2010

Re: how to control the pixel sizes of a Grid?

I gave it a last try: I bundled the code that creates the panels into
a single method, so that I can easily switch between the panel and no-
panel version. This should make sure that there are no other things in
the code that may cause the verttical space.

In the no-panel version I explicitly set the pixel size of the image.
But there is still the verrtical space. So by just switching 2 lines
of code you can verify that the Panel version works, but the non-panel-
version does not. There must be something wrong with the Image itself.
However, I verified (window.alert) that the image.getHeight returns

I can live with the panel version, but I cannot live with not knowing
what's wrong with the non-panel version. :-) I currently wonder if
there are some styles associated with the Image class. (How can one
retrieve the assoicated styles?) However, the Image style in gwt/
standard/standard.css is empty...

Below is my code. Maybe someone is also interested in finding out
what's going on there.



import ics.client.gui.brd.img.WikiMedia.Resources;

public class Board extends DockLayoutPanel
// cell type
private static final int CTP_CNR = 1; // corner
private static final int CTP_ANH = 2; // annotation, horizontal
private static final int CTP_ANV = 3; // annotation, vertical
private static final int CTP_CTR = 4; // center

private static final int cs = 50; // cell size:
private static final int as = 20; // annotation size

private int bs = cs * 8 + as * 2; // board size

public Grid grd = new Grid (8+2,8+2);


public Board ()
super (Unit.PX);
init ();

private void init ()
setPixelSize (bs,bs);

grd.setCellPadding (0);
grd.setCellSpacing (0);
grd.setBorderWidth (0);

// create corner cells

for (int y = 0;y < 10;y += 9)
for (int x = 0;x < 10;x += 9)
initCell (x,y,CTP_CNR);

// create border cells

for (int i = 1; i < 9; i++)
initCell (i,0,CTP_ANV);
initCell (i,9,CTP_ANV);
initCell (0,i,CTP_ANH);
initCell (9,i,CTP_ANH);

// create inner cells

for (int y = 1;y < 9;y++)
for (int x = 1;x < 9;x++)
initCell (x,y,CTP_CTR);

private void initCell (int x,int y,int ctp)
int xs,ys;
String s;
ImageResource r;

switch (ctp)
case CTP_CNR: xs = as; ys = as; s = "ics-Board-Annotation"; r =
null; break;
case CTP_ANH: xs = as; ys = cs; s = "ics-Board-Annotation"; r =
Resources.instance.nlh (); break;
case CTP_ANV: xs = cs; ys = as; s = "ics-Board-Annotation"; r =
Resources.instance.nlv (); break;
case CTP_CTR: xs = cs; ys = cs; s = ((x + y) % 2 != 0) ? "ics-Board-
Cell-B" : "ics-Board-Cell-W"; r = Resources.instance.nil (); break;
default: return;
SimplePanel p = createPanel (xs,ys,s);
grd.setWidget (y,x,p);
if (r != null)
Image i = new Image (Resources.instance.nil()); // (r);
i.setPixelSize (xs,ys);


grd.setWidget (y,x,i);


private SimplePanel createPanel (int xs,int ys,String stl)
SimplePanel p = new SimplePanel ();

p.setPixelSize (xs,ys);

p.addStyleName (stl);

return (p);


You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment