eclipse rcp Table 不能上下滚动
如图,该表格中数据当前页面显示不下,需要鼠标向下滚动,但是目前无法向下滚动,也可以发现没有向下的滚动条。创建这部分区域代码如下:
private void createSqlHisTable(Composite parent) { Composite composite = new Composite(parent,SWT.NONE); GridLayout gridLayout = new GridLayout(1, false); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.searchText = new Text(composite, SWT.BORDER); this.searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); sqlHisTable = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL); sqlHisTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // 重要 sqlHisTable.setData(this); sqlHisTable.setHeaderVisible(true); sqlHisTable.setMenu(createPopUpMenu()); sqlHisTable.addSelectionListener(widgetDefaultSelectedAdapter(e -> { TableItem[] items = sqlHisTable.getSelection(); if (items.length > 0) editEntry(items[0]); })); sqlHisTable.addSelectionListener(widgetSelectedAdapter(e -> { chosenTarget = "sqlHisTable"; })); for(int i = 0; i < columnNames.length; i++) { TableColumn column = new TableColumn(sqlHisTable, SWT.NONE); column.setText(columnNames[i]); column.setWidth(columnWidth[i]); final int columnIndex = i; column.addSelectionListener(widgetSelectedAdapter(e -> sort(columnIndex))); } // loadQMLogDataFromFile(); UIUtils.addFocusTracker(this.getSite(), SQL_INSPECTION_CONTROL_ID, sqlHisTable); sqlHisTable.addDisposeListener(e -> { // UIUtils.removeFocusTracker(SqlInspectionView.this.getSite(), sqlHisTable); QMUtils.unregisterMetaListener(this); UIUtils.dispose(sqlHisTable); }); }
设置table上下、左右滚动是在创建table时设置样式:
SWT.V_SCROLL | SWT.H_SCROLL
那么在当前组件 GridData 页面布局下,我对table设置了
sqlHisTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
这种水平填充,那么table可以左右滚动,如果需要设置table上下滚动 则需要设置
sqlHisTable.setLayoutData(new GridData(GridData.FILL_VERTICAL));
那么这里需要表格上下左右滚动,直接设置为
sqlHisTable.setLayoutData(new GridData(GridData.FILL_BOTH));
本文来自博客园,作者:margo,转载请注明原文链接:https://www.cnblogs.com/ZMargo/articles/13403882.html