📄 viewformsample.java
字号:
package rcpbook.swtjface.sample;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class ViewFormSample {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(280, 180);
shell.setText("ViewForm示例");
shell.setLayout(new FillLayout());
createContents(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void createContents(Shell shell) {
final ViewForm vf = new ViewForm(shell, SWT.FLAT | SWT.BORDER);
// 设置顶部左边的文字
CLabel clabel = new CLabel(vf, SWT.NONE);
clabel.setText("系统辅助处理");
vf.setTopLeft(clabel);
// 设置顶部工具栏
final ToolBar tbTool = new ToolBar(vf, SWT.FLAT);
final ToolItem dataBak = new ToolItem(tbTool, SWT.NONE);
dataBak.setImage(ImageDescriptor.createFromFile(ViewFormSample.class,
"images/dataBak.gif").createImage());
dataBak.setToolTipText("数据备份");
final ToolItem dataConfig = new ToolItem(tbTool, SWT.NONE);
dataConfig.setImage(ImageDescriptor.createFromFile(
ViewFormSample.class, "images/dataConfig.gif").createImage());
dataConfig.setToolTipText("数据源配置");
final ToolItem logoff = new ToolItem(tbTool, SWT.NONE);
logoff.setImage(ImageDescriptor.createFromFile(ViewFormSample.class,
"images/logoff.gif").createImage());
logoff.setToolTipText("用户注销");
final ToolItem user = new ToolItem(tbTool, SWT.NONE);
user.setImage(ImageDescriptor.createFromFile(ViewFormSample.class,
"images/user.gif").createImage());
user.setToolTipText("用户管理");
vf.setTopCenter(tbTool);
// 设置顶部右边工具栏
final ToolBar tbClose = new ToolBar(vf, SWT.FLAT);
final ToolItem close = new ToolItem(tbClose, SWT.NONE);
close.setImage(ImageDescriptor.createFromFile(ViewFormSample.class,
"images/close.gif").createImage());
close.setToolTipText("关闭");
close.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
vf.dispose();
}
});
vf.setTopRight(tbClose);
// 添加主体内容
Composite composite = new Composite(vf, SWT.FLAT);
Label label1 = new Label(composite, SWT.NONE);
label1.setText("这是一个简单的ViewForm测试程序!");
label1.setBounds(0, 0, 270, 80);
vf.setContent(composite);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -