各位大哥大姐,我用的是swt designer工具,在可视化设计的时候能看到组件,为什么在程序运行的时候就没有了呢 ?代码如下
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class CoolBarTest extends Shell { /**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
CoolBarTest shell = new CoolBarTest(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Create the shell
* @param display
* @param style
*/
public CoolBarTest(Display display, int style) {
super(display, style);
createContents();
setLayout(new FillLayout());
} /**
* Create contents of the window
*/
protected void createContents() {
setText("SWT Application");
setSize(378, 241); final ViewForm viewForm = new ViewForm(this, SWT.NONE); final CoolBar coolBar = new CoolBar(viewForm, SWT.NONE);
viewForm.setTopLeft(coolBar); final CoolItem newItemCoolItem = new CoolItem(coolBar, SWT.NONE);
newItemCoolItem.setText("New item"); final ToolBar toolBar = new ToolBar(coolBar, SWT.NONE);
newItemCoolItem.setControl(toolBar); final ToolItem newItemToolItem = new ToolItem(toolBar, SWT.PUSH);
newItemToolItem.setText("设置"); coolBar.layout();
viewForm.layout(); //
} protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
} }
各位大哥,大姐,组件为什么显示不出来呢?谢谢
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class CoolBarTest extends Shell { /**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
CoolBarTest shell = new CoolBarTest(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Create the shell
* @param display
* @param style
*/
public CoolBarTest(Display display, int style) {
super(display, style);
createContents();
setLayout(new FillLayout());
} /**
* Create contents of the window
*/
protected void createContents() {
setText("SWT Application");
setSize(378, 241); final ViewForm viewForm = new ViewForm(this, SWT.NONE); final CoolBar coolBar = new CoolBar(viewForm, SWT.NONE);
viewForm.setTopLeft(coolBar); final CoolItem newItemCoolItem = new CoolItem(coolBar, SWT.NONE);
newItemCoolItem.setText("New item"); final ToolBar toolBar = new ToolBar(coolBar, SWT.NONE);
newItemCoolItem.setControl(toolBar); final ToolItem newItemToolItem = new ToolItem(toolBar, SWT.PUSH);
newItemToolItem.setText("设置"); coolBar.layout();
viewForm.layout(); //
} protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
} }
各位大哥,大姐,组件为什么显示不出来呢?谢谢
解决方案 »
- 命令行中提示软件包不存在
- 请问如何将一串字符串中的英文引号转变成中文的引号,要考虑前后
- java socket 长连接
- 求GUI方面的电子书,谢谢!
- 还是数据库乱码问题!搞不明白!
- 谁能讲讲JRE与java虚拟机的关系???????
- Vector类和Hashtable类在效率上有哪些不同?
- 求记事本的一些简单的问题
- JTable问题.急
- 我在每题中都写了答案,我知道大多数是错的,请高手指教,谢谢
- JAVA GUI基础题目:怎么样才能是点击【帮助】里的【退出帮助】在弹出的窗口时,为要关闭这一个窗口,而不关闭菜单窗口和登陆界面的窗口?该怎么办啊 其他的不好的地方望帮我改正啊
- String.replace不工作?
用setSize()方法,
才能显示
这是版本差异造成d
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;public class demo extends Shell { /**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
demo shell = new demo(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Create the shell
*
* @param display
* @param style
*/
public demo(Display display, int style) {
super(display, style);
createContents();
setLayout(new FillLayout());
} /**
* Create contents of the window
*/
protected void createContents() {
setText("SWT Application");
setSize(378, 241); final ViewForm viewForm = new ViewForm(this, SWT.NONE); final CoolBar coolBar = new CoolBar(viewForm, SWT.NONE);
viewForm.setTopLeft(coolBar);
final CoolItem newItemCoolItem = new CoolItem(coolBar, SWT.NONE);
final ToolBar toolBar = new ToolBar(coolBar, SWT.NONE);
newItemCoolItem.setControl(toolBar);
newItemCoolItem.setText("New item");
final ToolItem newItemToolItem = new ToolItem(toolBar, SWT.PUSH);
newItemToolItem.setText("设置");
//添加setSize() toolBar.pack();
Point point = new Point(toolBar.getSize().x, toolBar.getSize().y);
newItemCoolItem.setSize(point);
coolBar.layout();
viewForm.layout();
//
} protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}}
//添加setSize()
toolBar.pack();
Point point = new Point(toolBar.getSize().x, toolBar.getSize().y);
newItemCoolItem.setSize(point);
coolBar.layout();
viewForm.layout();