java - How do I control the size of this shell without it being overridden? -


i need swt help.

i built shell multiple text labels. labels controlling size of shell, want shell 250x200 pixels. have size set before open shell. how keep being overridden? want able put in 1000 rows , able scroll down, instead of having giant window cannot with.

import org.eclipse.swt.swt; import org.eclipse.swt.widgets.display; import org.eclipse.swt.widgets.shell; import org.eclipse.swt.layout.griddata; import org.eclipse.swt.layout.gridlayout; import org.eclipse.swt.widgets.label; import org.eclipse.swt.graphics.point; import org.eclipse.swt.graphics.rectangle; import org.eclipse.swt.graphics.color;  public class javalabeltable {  private label status; private display display; private shell shell = new shell(display, swt.dialog_trim | swt.center | swt.v_scroll);  public javalabeltable(display display) {     initut(display); }  public void initut(display display) {     int q = 110;     int w = 40;     int e = q - w;     int i;     int y = 120;     int b = 1;     int c = 1;     shell.setlayout(new gridlayout(3, false));     label registerlabels[] = new label[y];     status = new label(shell, swt.border);      griddata gd2 = new griddata(swt.fill, swt.fill, true, true);        status.setlayoutdata(gd2);     gd2.widthhint = q;     gd2.heighthint = 15;     gd2.horizontalspan = 3;      for(i=1; i<y; i++)     {         if(i % 3 == 1)         {             griddata gd1 = new griddata(swt.fill, swt.fill, true, true);             registerlabels[i] = new label(shell, swt.none);             registerlabels[i].setlayoutdata(gd1);             registerlabels[i].setalignment(swt.center);             gd1.widthhint = w;             gd1.horizontalspan = 1;             registerlabels[i].settext(integer.tostring(b));             b++;         }         else         {             if(i % 3 == 2)             {                 griddata gd1 = new griddata(swt.fill, swt.fill, true, true);                 registerlabels[c] = new label(shell, swt.border);                 registerlabels[c].setlayoutdata(gd1);                 registerlabels[c].setalignment(swt.center);                 color col1 = new color(display, 255, 255, 255);                 registerlabels[c].setbackground(col1);                 gd1.widthhint = e;                 gd1.horizontalspan = 1;                 registerlabels[c].gettext();                 c++;             }             else             {                 griddata gd1 = new griddata(swt.fill, swt.fill, true, true);                 registerlabels[i] = new label(shell, swt.none);                 registerlabels[i].setlayoutdata(gd1);                 registerlabels[i].setalignment(swt.center);                 gd1.widthhint = 20;                 gd1.horizontalspan = 1;              }         }     }      shell.setsize(250, 200);     status.gettext();         shell.settext("running");     shell.pack();     centerwindow(shell);     shell.open();      while (!shell.isdisposed())  {     if (!display.readanddispatch())     {         display.sleep();     }} }  private void centerwindow(shell shell)  {      rectangle bds = shell.getdisplay().getbounds();      point p = shell.getsize();      int nleft = (bds.width - p.x) / 2;     int ntop = (bds.height - p.y) / 2;      shell.setbounds(nleft, ntop, p.x, p.y); }  @suppresswarnings("unused") public static void main(string[] args) {      display display = new display();     javalabeltable ex = new javalabeltable(display);     display.dispose(); }     } 

don't call shell.pack() - sets size of shell 'preferred' size determined size of contents.

pack() equivalent to:

setsize(computesize(swt.default, swt.default, true)); 

Comments