SWT(JFace)體驗之ViewForm的使用
更新時間:2009年06月25日 11:53:31 作者:
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做布局調整
在上一步創(chuàng)建好ActionGroup中的Action后,接下來就是要在界面中加上工具欄。先要將布局用ViewForm類來調整一下,ViewForm也是繼承自Composite的一個容器。原先表格是建立在Shell之上的,現在要在Shell上再插入一個ViewForm容器,以它為基座將工具欄和表格創(chuàng)建于其中,如圖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 //……和上一節(jié)相同的代碼(省略) //創(chuàng)建工具欄 ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT); // 創(chuàng)建一個ToolBar容器 ToolBarManager toolBarManager = new ToolBarManager(toolBar); // 創(chuàng)建一個toolBar的管理器 actionGroup.fillActionToolBars(toolBarManager); //將Action通過toolBarManager注入ToolBar中 // 設置表格和工具欄在布局中的位置 viewForm.setContent(tv.getControl()); // 主體:表格 viewForm.setTopLeft(toolBar); // 頂端邊緣:工具欄 shell.open(); |
![]() |
圖14.9 布局示意圖 |
相關文章
SpringBoot整合Swagger和Actuator的使用教程詳解
Swagger 是一套基于 OpenAPI 規(guī)范構建的開源工具,可以幫助我們設計、構建、記錄以及使用 Rest API。本篇文章主要介紹的是SpringBoot整合Swagger(API文檔生成框架)和SpringBoot整合Actuator(項目監(jiān)控)使用教程。感興趣的朋友一起看看吧2019-06-06Synchronized?和?ReentrantLock?的實現原理及區(qū)別
這篇文章主要介紹了Synchronized?和?ReentrantLock?的實現原理及區(qū)別,文章為榮啊主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09mybatis interceptor 處理查詢參數及查詢結果的實例代碼
這篇文章主要介紹了mybatis interceptor 處理查詢參數及查詢結果,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-01-01