您的位置:程序门 -> java -> gui 设计



table中嵌入checkbox的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


table中嵌入checkbox的问题
发表于:2008-02-23 22:54:13 楼主
下面的代码有2个问题:  
1.前三列都是checkbox,但是有2列老是重合到一块了,不知道为什么?  
2.用上下左右键移动表里的数据时三列checkbox会跟着浮动,但是用鼠标拉滚动条确没有问题  

望大虾们指点下


import   org.eclipse.swt.swt;
import   org.eclipse.swt.custom.tableeditor;
import   org.eclipse.swt.events.mouseevent;
import   org.eclipse.swt.events.mouselistener;
import   org.eclipse.swt.graphics.color;
import   org.eclipse.swt.graphics.font;
import   org.eclipse.swt.graphics.point;
import   org.eclipse.swt.layout.griddata;
import   org.eclipse.swt.layout.gridlayout;
import   org.eclipse.swt.widgets.button;
import   org.eclipse.swt.widgets.composite;
import   org.eclipse.swt.widgets.display;
import   org.eclipse.swt.widgets.shell;
import   org.eclipse.swt.widgets.table;
import   org.eclipse.swt.widgets.tablecolumn;
import   org.eclipse.swt.widgets.tableitem;

public   class   test2   {

public   static   final   display   display   =   new   display();

public   static     shell   shell   =   display.getactiveshell();
/**
  *   @param   args
  */
public   static   void   main(string[]   args)   {
try   {
//display   display   =   new   display();

shell[]   shells   =   display.getshells();
// shell   shell   =   display.getactiveshell();
if   (shell   ==   null)
shell   =   new   shell(display);
//shell   shell   =   new   shell(display);
int   hh   =   shell.handle;
gridlayout   gridlayout7   =   new   gridlayout();
gridlayout7.horizontalspacing   =   0;   //   generated
gridlayout7.marginwidth   =   0;   //   generated
gridlayout7.marginheight   =   0;   //   generated
gridlayout7.verticalspacing   =   0;   //   generated


shell.settext("test");
shell.setfont(new   font(display.getdefault(),
"\uff2d\uff33       \u30b4\u30b7\u30c3\u30af",   9,   swt.normal));

shell.setbackground(new   color(display.getcurrent(),   254,   250,   232));
shell.setlayout(gridlayout7);   //   generated
shell.setsize(new   point(854,   600));
shell.setbackgroundmode(swt.inherit_default);

gridlayout   gridlayout32   =   new   gridlayout();
gridlayout32.marginwidth   =   10;   //   generated
griddata   griddata11   =   new   griddata();
griddata11.horizontalalignment   =   griddata.fill;
griddata11.grabexcesshorizontalspace   =   true;
griddata11.grabexcessverticalspace   =   true;
griddata11.verticalalignment   =   griddata.fill;
griddata   griddata10   =   new   griddata();
griddata10.horizontalalignment   =   griddata.fill;
griddata10.grabexcesshorizontalspace   =   true;
griddata10.grabexcessverticalspace   =   true;
griddata10.verticalalignment   =   griddata.fill;
composite   composite5   =   new   composite(shell,   swt.none);
composite5.setlayoutdata(griddata11);
composite5.setlayout(gridlayout32);   //   generated
composite5.setfont(new   font(display.getdefault(),
"\uff2d\uff33       \u30b4\u30b7\u30c3\u30af",   9,   swt.normal));
final   table   table   =   new   table(composite5,   swt.border
¦   swt.full_selection);
table.setheadervisible(true);
table.setfont(new   font(display.getdefault(),
"\uff2d\uff33       \u30b4\u30b7\u30c3\u30af",   9,   swt.normal));
table.setlayoutdata(griddata10);
table.setlinesvisible(true);

tablecolumn   tablecolumn0   =   new   tablecolumn(table,   swt.center);
tablecolumn0.setwidth(25);   //   generated

tablecolumn   tablecolumn1   =   new   tablecolumn(table,   swt.center);
tablecolumn1.setwidth(40);   //   generated
tablecolumn1.settext("1");   //   generated

tablecolumn   tablecolumn2   =   new   tablecolumn(table,   swt.center);
tablecolumn2.setwidth(40);   //   generated
tablecolumn2.settext("2");   //   generated

tablecolumn   tablecolumn3   =   new   tablecolumn(table,   swt.none);
tablecolumn3.setwidth(140);   //   generated
tablecolumn3.settext("3");   //   generated

tablecolumn   tablecolumn4   =   new   tablecolumn(table,   swt.none);
tablecolumn4.setwidth(250);   //   generated
tablecolumn4.settext("4");   //   generated

tablecolumn   tablecolumn5   =   new   tablecolumn(table,   swt.none);
tablecolumn5.setwidth(250);   //   generated
tablecolumn5.settext("5");   //   generated

tablecolumn   tablecolumn51   =   new   tablecolumn(table,   swt.right);
tablecolumn51.setwidth(120);   //   generated
tablecolumn51.settext("6");   //   generated

tablecolumn   tablecolumn6   =   new   tablecolumn(table,   swt.none);
tablecolumn6.setwidth(80);   //   generated
tablecolumn6.settext("7");   //   generated






/*button   chkboxapp   =   new   button(table,   swt.check   ¦   swt.center);
chkboxapp.setlocation(1,   1);
        point   bsize   =   chkboxapp.computesize(swt.default,   swt.default);

        //   otherwise   an   image   is   stretched   by   width
        bsize.x   =   math.max(bsize.x   -   1,   bsize.y   -   1);
        bsize.y   =   math.max(bsize.x   -   1,   bsize.y   -   1);
        chkboxapp.setsize(bsize);
        table.setsize(bsize);
button   chkboxapp1   =   new   button(table,   swt.check   ¦   swt.center);
chkboxapp1.setlocation(28,   1);

button   chkboxapp2   =   new   button(table,   swt.check   ¦   swt.center);
chkboxapp1.setlocation(70,   1);

tableitem   ti   =   new   tableitem(table,   swt.none);
tableeditor   teapproval   =   new   tableeditor(table);
teapproval.grabhorizontal   =   true;
teapproval.seteditor(chkboxapp,   ti,   0);
teapproval.seteditor(chkboxapp1,   ti,   1);
teapproval.seteditor(chkboxapp2,   ti,   2);

chkboxapp.setlocation(10,   20);
chkboxapp1.setlocation(30,   30);
chkboxapp2.setlocation(50,   50);

ti.settext(3,   "sss");
ti.settext(4,   "sss");
ti.settext(5,   "sss");
ti.settext(6,   "sss");
ti.settext(7,   "sss");/*****/


gridlayout   gridlayoutbottom   =   new   gridlayout();
gridlayoutbottom.marginwidth   =   10;   //   generated
griddata   griddatabottom   =   new   griddata();
griddatabottom.horizontalalignment   =   griddata.fill;
griddatabottom.grabexcesshorizontalspace   =   true;
griddatabottom.grabexcessverticalspace   =   true;
griddatabottom.verticalalignment   =   griddata.fill;
griddata   griddatabotto   =   new   griddata();
griddatabotto.horizontalalignment   =   griddata.fill;
griddatabotto.grabexcesshorizontalspace   =   true;
griddatabotto.grabexcessverticalspace   =   true;
griddatabotto.verticalalignment   =   griddata.fill;
composite   compositebottom   =   new   composite(shell,   swt.none);
compositebottom.setlayoutdata(griddatabottom);
compositebottom.setlayout(gridlayoutbottom);   //   generated
compositebottom.setfont(new   font(display.getdefault(),
"\uff2d\uff33       \u30b4\u30b7\u30c3\u30af",   9,   swt.normal));
button   buttonbottom   =   new   button(compositebottom,   swt.none);
buttonbottom.settext("add");
buttonbottom.addmouselistener(new   mouselistener()   {
public   void   mousedoubleclick(mouseevent   e)   {

}

public   void   mousedown(mouseevent   e)   {

}

public   void   mouseup(mouseevent   e)   {

tableitem   ti   =   new   tableitem(table,   swt.none);

tableeditor   teapproval   =   new   tableeditor(table);
teapproval.grabhorizontal   =   true;

button   chkboxapp   =   new   button(table,   swt.check   ¦   swt.center);
teapproval.seteditor(chkboxapp,   ti,   0);

button   chkboxapp2   =   new   button(table,   swt.check   ¦   swt.center);
teapproval.seteditor(chkboxapp2,   ti,   1);

button   chkboxapp3   =   new   button(table,   swt.check   ¦   swt.center);
teapproval.seteditor(chkboxapp3,   ti,   2);

ti.settext(3,   "sss");
ti.settext(4,   "sss");
ti.settext(5,   "sss");
ti.settext(6,   "sss");
ti.settext(7,   "sss");
}
});

shell.open();

while   (!shell.isdisposed())   {
if   (!display.readanddispatch())
display.sleep();
}

display.dispose();
}   catch   (exception   e)   {
e.printstacktrace();
}
}

}


快速检索

最新资讯
热门点击