Eclipse Nebula 部件入门1

转自https://www6.software.ibm.com/developerworks/cn/education/opensource/os-eclipse-nebula/section14.html

Eclipse Nebula 部件入门

Eclipse Nebula 的 Grid、CDateTime、CompositeTable、PGroup 和 PShelf 部件快速入门指南

developerWorks
前一页第 14 页,共 21 页后一页

文档选项
将打印机的版面设置成横向打印模式

打印本页


对本教程的评价

帮助我们改进这些内容


创建 Grid 条目树和列跨距

Grid 将允许您创建 GridItem 树,表示条目与子条目之间的关系。虽然简单的一层嵌套或两层嵌套更为常见,但是条目可以嵌套 n 层深。要创建条目树,请执行以下步骤:

  1. 在相应的 GridColumn 上,调用 setTree() 方法,传入 true 值。这将把列指定为允许包含子条目树的列。切换分支对象视图的 UI 控件显示在此列中。
  2. 创建树的根 GridItem。此 GridItem 应当以 Grid 为其父节点。
  3. 创建树的下一级分支 GridItem。为此,把对父对象的引用(在本例中为树的根)传递给每个分支 GridItem 的构造函数。对每一级树重复执行此步骤。传递给每个条目的构造函数的父对象是树中高于该父对象一个级别的 GridItem 对象。

GridItem 中的数据字段也可以被设为跨度多个列。为此,调用相应的 GridItem 的 setColumnSpan(int,int) 方法。第一个参数是将受影响的列的索引;第二个参数将指定将跨度的后续列数。

在清单 7 中,将创建 GridItem 树来把汽车分组到特定的租用分类中。分类列被设为横向跨度所有列。它的背景颜色和字体也被更改。


清单 7. GridExample3
                    
public class GridExample3 {
	public static void main(String... args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

	           Grid grid = new Grid(shell, SWT.BORDER | 
				SWT.V_SCROLL | SWT.H_SCROLL);
			   grid.setHeaderVisible(true);

	           		  Car car1 = new Car(133, "2007","Chevy", 
						"Cobalt",Car.CarType.COUPE, 4321, "Yellow", true);
|-------10--------20--------30--------40--------50--------60--------70--------80--------9|
|-------- XML error:  The previous line is longer than the max of 90 characters ---------|
                      Car car2 = new Car(134, "2007","Chevy", 
						"Cobalt",Car.CarType.COUPE, 4321, "Yellow", true);
|-------10--------20--------30--------40--------50--------60--------70--------80--------9|
|-------- XML error:  The previous line is longer than the max of 90 characters ---------|
                      Car car3 = new Car(135, "2006","Ford", 
						"Focus",Car.CarType.COUPE, 15343, "Red", true);
|-------10--------20--------30--------40--------50--------60--------70--------80--------9|
|-------- XML error:  The previous line is longer than the max of 90 characters ---------|
                      Car car4 = new Car(136, "2006","Chrysler", 
						"Sebring",Car.CarType.SEDAN, 12932, "Black", false);
|-------10--------20--------30--------40--------50--------60--------70--------80--------9|
|-------- XML error:  The previous line is longer than the max of 90 characters ---------|
                      Car car5 = new Car(137, "2002","Ford", 
						"Mustang",Car.CarType.COUPE,4342, "Red", true);
|-------10--------20--------30--------40--------50--------60--------70--------80--------9|
|-------- XML error:  The previous line is longer than the max of 90 characters ---------|

                      GridColumn rentalTypeColumn = new GridColumn(grid, SWT.NONE);
		rentalTypeColumn.setText("Rental Grade");
		rentalTypeColumn.setWidth(100);
		rentalTypeColumn.setTree(true);
		
		GridColumn idColumn = new GridColumn(grid, SWT.NONE);
		idColumn.setText("Car Number");
		idColumn.setWidth(100);
				
		GridColumn yearColumn = new GridColumn(grid, SWT.NONE);
		yearColumn.setText("Year");
		yearColumn.setWidth(50);

		GridColumn makeColumn = new GridColumn(grid, SWT.NONE);
		makeColumn.setText("Make");
		makeColumn.setWidth(100);

                      GridColumn modelColumn = new GridColumn(grid, SWT.NONE);
		modelColumn.setText("Model");
		modelColumn.setWidth(100);

		GridColumn typeColumn = new GridColumn(grid, SWT.NONE);
		typeColumn.setText("Type");
		typeColumn.setWidth(100);
		
	           GridColumn availableColumn = new GridColumn(grid, 
				SWT.CHECK | SWT.CENTER);
		availableColumn.setText("Available");
		availableColumn.setWidth(75);
		
		GridItem compactItem = new GridItem(grid, SWT.CENTER);
		compactItem.setText(0, "Compact");

	           compactItem.setFont(new Font(null, 
				"Arial", 18, SWT.BOLD | SWT.ITALIC));
		compactItem.setColumnSpan(0, 6);
		compactItem.setBackground(0, new Color(null, 0,255,0));
		
		GridItem item1 = new GridItem(compactItem, SWT.NONE);
		item1.setText(1, String.valueOf(car1.getCarNumber()));
		item1.setText(2,car1.getYear());
		item1.setText(3, car1.getMake());
		item1.setText(4, car1.getModel());
		item1.setText(5, car1.getCarType().toString());
		item1.setChecked(6, car1.isAvailable());
		

		GridItem item2 = new GridItem(compactItem, SWT.NONE);
		item2.setText(1, String.valueOf(car2.getCarNumber()));
		item2.setText(2,car2.getYear());
		item2.setText(3, car2.getMake());
		item2.setText(4, car2.getModel());
		item2.setText(5, car2.getCarType().toString());
		item2.setChecked(6, car2.isAvailable());
		
		GridItem item3 = new GridItem(compactItem, SWT.NONE);
		item3.setText(1, String.valueOf(car3.getCarNumber()));
		item3.setText(2, car3.getYear());
		item3.setText(3, car3.getMake());
		item3.setText(4, car3.getModel());
		item3.setText(5, car3.getCarType().toString());
		item3.setChecked(6, car3.isAvailable());
		
		GridItem midSizedItem = new GridItem(grid, SWT.NONE);
		midSizedItem.setText(0, "Mid-Sized");

                      midSizedItem.setFont(new Font(null, 
						"Arial", 18, SWT.BOLD | SWT.ITALIC));
		midSizedItem.setColumnSpan(0,6);
		midSizedItem.setBackground(0, new Color(null, 0, 255, 255));
		
		GridItem item4 = new GridItem(midSizedItem, SWT.NONE);
		item4.setText(1, String.valueOf(car4.getCarNumber()));
		item4.setText(2,car4.getYear());
		item4.setText(3, car4.getMake());
		item4.setText(4, car4.getModel());
		item4.setText(5, car4.getCarType().toString());
		item4.setChecked(6, car4.isAvailable());
		
		GridItem item5 = new GridItem(midSizedItem, SWT.NONE);
		item5.setText(1, String.valueOf(car5.getCarNumber()));
		item5.setText(2,car5.getYear());
		item5.setText(3, car5.getMake());
		item5.setText(4, car5.getModel());
		item5.setText(5, car5.getCarType().toString());
		item5.setChecked(6, car5.isAvailable());
		
		shell.setSize(700, 200);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}

运行示例将提供如下所示的结果。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值