---
title: "ViewForm"
author: "longcxm"
date: "2012-12-16T14:53:09Z"
tags: []
categories: ["编程语言"]
slug: "viewform"
draft: false
lastmod: "2012-12-16T14:53:09Z"
id: 1748636
url: "https://longcxm.iteye.com/blog/1748636"
---

ViewForm是一个容器，它是编辑器的基座，用来容纳工具栏和文本框，ToolBar是一个工具栏，同时可以容纳一个工具栏按钮ToolItem

 

```
		ViewForm vf=new ViewForm(shell, SWT.NONE);
		vf.setLayout(new FillLayout());
		
		final Text text=new Text(vf, SWT.BORDER|SWT.V_SCROLL);
		vf.setContent(text);
		
		ToolBar tb=new ToolBar(vf, SWT.NONE);
		ToolItem ti=new ToolItem(tb, SWT.PUSH);
		ti.setText("取得");
		ti.addSelectionListener(new SelectionAdapter()
		{
			@Override
			public void widgetSelected(SelectionEvent arg0) {
				// TODO Auto-generated method stub
				MessageDialog.openInformation(null, null, text.getText());
			}
			
		});
		
		
		ToolItem ti2=new ToolItem(tb, SWT.PUSH);
		ti2.setText("删除");
		ti2.addSelectionListener(new SelectionAdapter()
		{
			@Override
			public void widgetSelected(SelectionEvent arg0) {
				text.setText("");
			}
			
		});
		
		vf.setTopLeft(tb);
```