package test;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.layout.FillLayout;
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.Group;
import org.eclipse.swt.widgets.ProgressBar;
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 testTableEdit {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM); //显示的窗口
shell.setLayout(new FillLayout());
TableViewer poTabView = new TableViewer(shell,SWT.FULL_SELECTION|SWT.BORDER);
Table poTable = poTabView.getTable();
poTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
poTable.setLinesVisible(true);
poTable.setHeaderVisible(true);
TableColumn poNo = new TableColumn(poTable, SWT.NONE);
// TableViewerColumn poNoview = new TableViewerColumn(poTabView, SWT.NONE);
// TableColumn poNo = poNoview.getColumn();
poNo.setText("订单号");
poNo.setWidth(70);
TableViewerColumn producview = new TableViewerColumn(poTabView, SWT.NONE);
TableColumn product = producview.getColumn();
product.setText("产出产品");
product.setWidth(120);
TableViewerColumn pCountview = new TableViewerColumn(poTabView, SWT.NONE);
TableColumn pCount = pCountview.getColumn();
pCount.setText("需求量/产出量");
pCount.setWidth(100);
TableViewerColumn progressView = new TableViewerColumn(poTabView, SWT.NONE);
TableColumn progress = progressView.getColumn();
progress.setText("完成百分比");
progress.setWidth(150);
// String count = String.valueOf(poModel.getTargetAmount())
// +"/"+String.valueOf(poModel.getActualFinishAmount());
TableItem poItem = new TableItem(poTable, SWT.BORDER);
poItem.setText(new String[]{"11","好货","20/10"});
TableEditor Tedit = new TableEditor(poTable);//创建表格编辑器
// Tedit.horizontalAlignment = SWT.LEFT;
// Tedit.minimumWidth = 100;
//在表格上创建comp
// Composite barComp = new Composite(poTable, SWT.NONE);
// barComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// GridLayout gld = new GridLayout();
// gld.marginWidth=0;
// gld.marginHeight=0;
// barComp.setLayout(gld);
// ProgressBar bar = new ProgressBar(barComp, SWT.HORIZONTAL| SWT.SMOOTH);
ProgressBar bar = new ProgressBar(poTable, SWT.HORIZONTAL| SWT.SMOOTH);
bar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
bar.setSelection(50);
Tedit.grabHorizontal = true;
// Tedit.minimumHeight = bar.getSize().y;
// Tedit.minimumWidth = bar.getSize().x;
Tedit.setEditor(bar, poItem,3);//把comp放到表格上的哪列;
// poItem.setData(UIConstants.EDITOR_BUTTON_DELETE, bar);
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
如图所示,可以拉伸表格,里边控件也跟着拉伸。