SWT(JFace)体验之ViewForm的使用
2019/7/7 19:30:00
本文主要是介绍SWT(JFace)体验之ViewForm的使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
代码如下:
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做布局调整
复制代码 代码如下:
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); //布局基座ViewForm viewForm.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 布局示意图 |
这篇关于SWT(JFace)体验之ViewForm的使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)