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做布局調(diào)整
在上一步創(chuàng)建好ActionGroup中的Action后,接下來就是要在界面中加上工具欄。先要將布局用ViewForm類來調(diào)整一下,ViewForm也是繼承自Composite的一個容器。原先表格是建立在Shell之上的,現(xiàn)在要在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中 // 設(shè)置表格和工具欄在布局中的位置 viewForm.setContent(tv.getControl()); // 主體:表格 viewForm.setTopLeft(toolBar); // 頂端邊緣:工具欄 shell.open(); |
![]() |
| 圖14.9 布局示意圖 |
相關(guān)文章
淺談springboot項目中定時任務(wù)如何優(yōu)雅退出
這篇文章主要介紹了淺談springboot項目中定時任務(wù)如何優(yōu)雅退出?具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
java?webservice超時時間設(shè)置方法代碼
當(dāng)我們使用WebService進行調(diào)用時,有時會出現(xiàn)超時的情況,下面這篇文章主要給大家介紹了關(guān)于java?webservice超時時間設(shè)置方法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01
Spring AspectJ 實現(xiàn)AOP的方法你了解嗎
這篇文章主要為大家介紹了Spring AspectJ 實現(xiàn)AOP的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-01-01
java中BCryptPasswordEncoder密碼的加密與驗證方式
這篇文章主要介紹了java中BCryptPasswordEncoder密碼的加密與驗證方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08
SpringBoot讀取properties或者application.yml配置文件中的數(shù)據(jù)
這篇文章主要介紹了SpringBoot讀取properties或者application.yml配置文件中的數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06


