如何固定jface中的Table组件的checkbox

 

package test;

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 Test {

 /**
  * @param args
  */
 @SuppressWarnings("unused")
 public static void main(String[] args) {
  try {
   Display display = new Display();
   Shell shell = new Shell(display);

   GridLayout gridLayout7 = new GridLayout();
   gridLayout7.horizontalSpacing = 0; // Generated
   gridLayout7.marginWidth = 0; // Generated
   gridLayout7.marginHeight = 0; // Generated
   gridLayout7.verticalSpacing = 0; // Generated

   if (shell == null)
    shell = new Shell();

   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

   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;
     // chkboxApp.setBackground(Const.WHITE_COLOR);

     Button chkboxApp = new Button(table, SWT.CHECK | SWT.LEFT);
     teApproval.setEditor(chkboxApp, ti, 0);

     Button chkboxApp2 = new Button(table, SWT.CHECK | SWT.LEFT);
     teApproval.setEditor(chkboxApp2, ti, 1);

     Button chkboxApp3 = new Button(table, SWT.CHECK | SWT.LEFT);
     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) {

  }
 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值