org.eclipse.swt.widgets.Table组件中嵌入checkbox怎么固定阿,现在的问题是用鼠标滚动没问题,但是用上下左右键时,checkbox会跟着滚动条走,有点类似form中的checkbox,但这个是jface中的组件,那位大虾指点一下

解决方案 »

  1.   

    更正下org.eclipse.swt.widgets.Table不是jface中的组件,没用到jface中的组件,不好意思哈
      

  2.   

    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
     */
    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) {

    }
    }}
      

  3.   

    上面的代码有2个问题:
    1.前三列都是checkbox,但是有2列老是重合到一块了,不知道为什么?
    2.用上下左右键移动表里的数据时三列checkbox会跟着浮动,但是用鼠标拉滚动条确没有问题望大虾们指点下