SWT(JFace)體驗(yàn)之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做布局調(diào)整
在上一步創(chuàng)建好ActionGroup中的Action后,接下來就是要在界面中加上工具欄。先要將布局用ViewForm類來調(diào)整一下,ViewForm也是繼承自Composite的一個(gè)容器。原先表格是建立在Shell之上的,現(xiàn)在要在Shell上再插入一個(gè)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)建一個(gè)ToolBar容器 ToolBarManager toolBarManager = new ToolBarManager(toolBar); // 創(chuàng)建一個(gè)toolBar的管理器 actionGroup.fillActionToolBars(toolBarManager); //將Action通過toolBarManager注入ToolBar中 // 設(shè)置表格和工具欄在布局中的位置 viewForm.setContent(tv.getControl()); // 主體:表格 viewForm.setTopLeft(toolBar); // 頂端邊緣:工具欄 shell.open(); |
![]() |
圖14.9 布局示意圖 |
相關(guān)文章
SpringBoot防止大量請(qǐng)求攻擊的實(shí)現(xiàn)
在有些特定的時(shí)候需要加上IP訪問時(shí)間限制,防止一個(gè)IP多次訪問請(qǐng)求,本文主要介紹了SpringBoot防止大量請(qǐng)求攻擊的實(shí)現(xiàn),感興趣的可以了解一下2021-11-11SpringBoot整合Swagger和Actuator的使用教程詳解
Swagger 是一套基于 OpenAPI 規(guī)范構(gòu)建的開源工具,可以幫助我們?cè)O(shè)計(jì)、構(gòu)建、記錄以及使用 Rest API。本篇文章主要介紹的是SpringBoot整合Swagger(API文檔生成框架)和SpringBoot整合Actuator(項(xiàng)目監(jiān)控)使用教程。感興趣的朋友一起看看吧2019-06-06Synchronized?和?ReentrantLock?的實(shí)現(xiàn)原理及區(qū)別
這篇文章主要介紹了Synchronized?和?ReentrantLock?的實(shí)現(xiàn)原理及區(qū)別,文章為榮啊主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09springMVC 用戶登錄權(quán)限驗(yàn)證實(shí)現(xiàn)過程解析
這篇文章主要介紹了springMVC 用戶登錄權(quán)限驗(yàn)證實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11idea搭建可運(yùn)行Servlet的Web項(xiàng)目
在網(wǎng)上看到一篇很詳細(xì)的 intelliJ IDEA 創(chuàng)建web項(xiàng)目并簡(jiǎn)單部署servlet的圖文教程,今天自己也配置一下,留個(gè)筆記,感興趣的可以了解一下2021-06-06mybatis interceptor 處理查詢參數(shù)及查詢結(jié)果的實(shí)例代碼
這篇文章主要介紹了mybatis interceptor 處理查詢參數(shù)及查詢結(jié)果,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01