SWT中在表格上添加 控件,TableEditor的使用

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();
 }
 
 }

如图所示,可以拉伸表格,里边控件也跟着拉伸。

 


 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值