Java SWT-使表格可滚动

Java SWT-使表格可滚动,java,eclipse-plugin,swt,jface,Java,Eclipse Plugin,Swt,Jface,我已经尝试了下面的代码,该表显示时没有任何滚动条。请帮助使SWT表格可以水平和垂直滚动 package snippet; import org.eclipse.swt.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class Snippet { public static void main(String[] args) { Display displ

我已经尝试了下面的代码,该表显示时没有任何滚动条。请帮助使SWT表格可以水平和垂直滚动

    package snippet;

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);

        createUI(shell);


        shell.pack();
        shell.open();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }

    private static void createUI(Shell shell) {
        // TODO Auto-generated method stub
        GridLayout layout = new GridLayout(1, false);


        shell.setLayout(layout);


        Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION|SWT.CHECK|SWT.RESIZE|SWT.SCROLL_PAGE);
        GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true);
        gd_table.heightHint = 136;
        gd_table.widthHint = 205;
        table.setLayoutData(gd_table);
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
        tblclmnNewColumn.setWidth(37);        

        TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
        tblclmnNewColumn_1.setWidth(219);
        tblclmnNewColumn_1.setText("Item ID");

        TableColumn tblclmnNewColumn_2 = new TableColumn(table, SWT.NONE);
        tblclmnNewColumn_2.setWidth(246);
        tblclmnNewColumn_2.setText("Revision ID");

        TableColumn tblclmnNewColumn_3 = new TableColumn(table, SWT.NONE);
        tblclmnNewColumn_3.setWidth(246);
        tblclmnNewColumn_3.setText("Vendor Name");

        TableColumn tblclmnNewColumn_4 = new TableColumn(table, SWT.NONE);
        tblclmnNewColumn_4.setWidth(246);
        tblclmnNewColumn_4.setText("Vendor ID");

        for(int i=0;i<10;i++)
        {
            TableItem item = new TableItem(table, SWT.NONE);

            item.setText(1,"item_id"+i);
            item.setText(2,"item_revision_id"+i);
            item.setText(3,"object_string"+i);
        }

    }

}
包片段;
导入org.eclipse.swt.*;
导入org.eclipse.swt.layout.*;
导入org.eclipse.swt.widgets.*;
公共类代码段{
公共静态void main(字符串[]args){
显示=新显示();
外壳=新外壳(显示);
createUI(shell);
shell.pack();
shell.open();
而(!shell.isDisposed()){
如果(!display.readAndDispatch())display.sleep();
}
display.dispose();
}
私有静态void createUI(Shell){
//TODO自动生成的方法存根
GridLayout=新的GridLayout(1,false);
shell.setLayout(布局);
Table Table=新表(shell,SWT.BORDER | SWT.FULL |选择| SWT.CHECK | SWT.RESIZE | SWT.SCROLL |页面);
GridData gd_table=新的GridData(SWT.FILL,SWT.FILL,true,true);
gd_table.heightHint=136;
gd_table.widthHint=205;
表.setLayoutData(gd_表);
表.setheadervible(true);
表.setLinesVisible(真);
TableColumn tblclmnNewColumn=新的TableColumn(表,SWT.NONE);
tblclmnNewColumn.设置宽度(37);
TableColumn tblclmnNewColumn_1=新的TableColumn(表,SWT.NONE);
tblclmnNewColumn_1.设置宽度(219);
tblclmnNewColumn_1.SETEXT(“项目ID”);
TableColumn tblclmnNewColumn_2=新的TableColumn(表,SWT.NONE);
tblclmnNewColumn_2.设置宽度(246);
tblclmnNewColumn_2.setText(“修订ID”);
TableColumn tblclmnNewColumn_3=新的TableColumn(表,SWT.NONE);
tblclmnNewColumn_3.设置宽度(246);
tblclmnNewColumn_3.SETEXT(“供应商名称”);
TableColumn tblclmnNewColumn_4=新的TableColumn(表,SWT.NONE);
tblclmnNewColumn_4.设置宽度(246);
tblclmnNewColumn_4.setText(“供应商ID”);

对于(int i=0;i您要查找的值是
SWT.V\u SCROLL
SWT.H\u SCROLL
。如果您将
SWT.SCROLL\u页面
构造函数中的
SWT.SCROLL\u常量替换为这两个,则代码将按预期工作


<代码>表=新表(Shell,SWT边界,SWORL选择,SW.T.SW.ReStudio,SW.V.Loopy.SWT.HYRONG);

@ MuHaMediqZas,乐于助人!请考虑标记为接受,以帮助关注未解决的问题。