SWT(JFace)体验之ViewForm的使用
时间:2023-10-20 13:02:01
代码如下:
package swt_jface.demo9;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class ViewFormExample {
Display display = new Display();
Shell shell = new Shell(display);
public ViewFormExample() {
shell.setLayout(new FillLayout());
final ViewForm viewForm = new ViewForm(shell, SWT.BORDER);
Label label = new Label(viewForm, SWT.NULL);
label.setText("Top center");
viewForm.setTopCenter(label);
shell.setSize(400, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new ViewFormExample();
}
}
用ViewForm做布局调整
在上一步创建好ActionGroup中的Action后,接下来就是要在界面中加上工具栏。先要将布局用ViewForm类来调整一下,ViewForm也是继承自Composite的一个容器。原先表格是建立在Shell之上的,现在要在Shell上再插入一个ViewForm容器,以它为基座将工具栏和表格创建于其中,如图14.9所示。
将原主程序中的open()方法修改如下,其他代码不变:
shell.setLayout(new FillLayout());ViewForm viewForm = new ViewForm(shell, SWT.NONE); //布局基座ViewFormviewForm.setLayout(new FillLayout());final TableViewer tv = new TableViewer(viewForm, SW… //父容器由shell改为viewForm//……和上一节相同的代码(省略)//创建工具栏ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT); // 创建一个ToolBar容器ToolBarManager toolBarManager = new ToolBarManager(toolBar); // 创建一个toolBar的管理器actionGroup.fillActionToolBars(toolBarManager); //将Action通过toolBarManager注入ToolBar中// 设置表格和工具栏在布局中的位置viewForm.setContent(tv.getControl()); // 主体:表格viewForm.setTopLeft(toolBar); // 顶端边缘:工具栏shell.open(); |
![]() |
图14.9 布局示意图 |
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中局部变量和成员变量的区别详解
![](https://img.aspxhome.com/file/2023/9/85829_0s.webp)
Java使用自动化部署工具Gradle中的任务设定教程
![](https://img.aspxhome.com/file/2023/7/89577_0s.png)
java微信公众号企业付款开发
![](https://img.aspxhome.com/file/2023/1/88041_0s.jpg)
SpringBoot+docker环境变量配置详解
![](https://img.aspxhome.com/file/2023/6/84756_0s.png)
C#程序执行时间长查询速度慢解决方案
Java中IO流简介_动力节点Java学院整理
![](https://img.aspxhome.com/file/2023/8/97788_0s.png)
Android开发双向滑动选择器范围SeekBar实现
![](https://img.aspxhome.com/file/2023/2/125372_0s.gif)
Java将Date日期类型字段转换成json字符串的方法
![](https://img.aspxhome.com/file/2023/0/61290_0s.png)
关于Java中String类字符串的解析
![](https://img.aspxhome.com/file/2023/3/91733_0s.png)
Spring Cloud负载均衡及远程调用实现详解
![](https://img.aspxhome.com/file/2023/9/132189_0s.png)
JAVA各种OOM代码示例与解决方法
![](https://img.aspxhome.com/file/2023/5/72555_0s.jpg)
JavaMail入门教程之接收邮件(4)
![](https://img.aspxhome.com/file/2023/1/80321_0s.jpg)
基于javassist进行动态编程过程解析
Android开发两个activity之间传值示例详解
浅谈Java内存区域与对象创建过程
SpringBoot使用MyBatis-Plus解决Invalid bound statement异常
C语言实现两个矩阵相乘
![](https://img.aspxhome.com/file/2023/6/103076_0s.png)
C#图片切割、图片压缩、缩略图生成代码汇总
Android简单使用PopupWindow的方法
![](https://img.aspxhome.com/file/2023/2/94252_0s.jpg)
Android悬浮按钮点击返回顶部FloatingActionButton
![](https://img.aspxhome.com/file/2023/8/117138_0s.gif)