请问我的程序(使用SWT,平台是Eclipse)为什么在初次运行的时候没有显示出想要的带有单选框和复选框界面,而只是一个空白面板呢?另外我还想问下如何设置Shell的属性使其大小不可更改呢(如最大化最小化按钮失效,Shell大小不可变)?望高手指教,以下是程序源代码package DemoComposite;import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.FillLayout;public class DemoComposite2
{
private Display display =null;
private Shell shell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Composite composite1 = null;
private Composite composite2 = null;
private Button radioButton1 = null;
private Button radioButton2 = null;
private Button checkBox1 = null;
private Button checkBox2 = null; /**
* This method initializes shell
*/
public DemoComposite2(){
createShell();
shell.open();
while (!shell.isDisposed()){
if(display.readAndDispatch())
display.sleep();
}
shell.dispose();
}
private void createShell()
{
display =new Display();
shell = new Shell(display);
shell.setText("容器演示");
createComposite1();
createComposite2();
shell.setSize(new Point(371, 211));
shell.setLayout(new FillLayout());
} /**
* This method initializes composite1
*
*/
private void createComposite1()
{
composite1 = new Composite(shell, SWT.NONE);
composite1.setLayout(new GridLayout());
composite1.setBackground(new Color(Display.getCurrent(), 236, 150, 216));
radioButton1 = new Button(composite1, SWT.RADIO);
radioButton1.setText("liu li");
radioButton2 = new Button(composite1, SWT.RADIO);
radioButton2.setText("Zhang li");
} /**
* This method initializes composite2
*
*/
private void createComposite2()
{
composite2 = new Composite(shell, SWT.NONE);
composite2.setLayout(new RowLayout(SWT.VERTICAL));
composite2.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
checkBox2 = new Button(composite2, SWT.CHECK);
checkBox2.setText("Zhang li");
checkBox1 = new Button(composite2, SWT.CHECK);
checkBox1.setText("Liu li");
}
public static void main(String[] args)
{
new DemoComposite2();
}}
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.FillLayout;public class DemoComposite2
{
private Display display =null;
private Shell shell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Composite composite1 = null;
private Composite composite2 = null;
private Button radioButton1 = null;
private Button radioButton2 = null;
private Button checkBox1 = null;
private Button checkBox2 = null; /**
* This method initializes shell
*/
public DemoComposite2(){
createShell();
shell.open();
while (!shell.isDisposed()){
if(display.readAndDispatch())
display.sleep();
}
shell.dispose();
}
private void createShell()
{
display =new Display();
shell = new Shell(display);
shell.setText("容器演示");
createComposite1();
createComposite2();
shell.setSize(new Point(371, 211));
shell.setLayout(new FillLayout());
} /**
* This method initializes composite1
*
*/
private void createComposite1()
{
composite1 = new Composite(shell, SWT.NONE);
composite1.setLayout(new GridLayout());
composite1.setBackground(new Color(Display.getCurrent(), 236, 150, 216));
radioButton1 = new Button(composite1, SWT.RADIO);
radioButton1.setText("liu li");
radioButton2 = new Button(composite1, SWT.RADIO);
radioButton2.setText("Zhang li");
} /**
* This method initializes composite2
*
*/
private void createComposite2()
{
composite2 = new Composite(shell, SWT.NONE);
composite2.setLayout(new RowLayout(SWT.VERTICAL));
composite2.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
checkBox2 = new Button(composite2, SWT.CHECK);
checkBox2.setText("Zhang li");
checkBox1 = new Button(composite2, SWT.CHECK);
checkBox1.setText("Liu li");
}
public static void main(String[] args)
{
new DemoComposite2();
}}
解决方案 »
- 关于java贪食蛇的问题,,求各种指导
- 遍历Vector的问题。两种结构,其中一种速度过慢,向各位高手求助!
- 如何让批处理文件出错时不关闭窗口
- 请教一个关于路径的问题
- Hi eveyone, 我有一个如何比较两个大VO对象是否相等的问题,请大家帮忙,谢谢
- 在安装好j2sdk1.4.2_02系统后发现的问题
- 关于对象在内存中的存储问题??
- 不能发表帖子,你不能发这么多可用分
- 谁知道怎样改变一个java.lang.Long对象的值吗??谢谢了!!
- 怎样一行一行地读文本文件并把每一行区分的?谢谢!
- 我在编写程序时用到org.jdesktop.layout.GroupLayout
- 为什么我的滚动条显示不出来
composite1、composite2没有layoutdate
composite1、composite2没有layoutdate
{
display =new Display();
shell = new Shell(display);
shell.setText("容器演示");
createComposite1();
createComposite2();
shell.setSize(new Point(371, 211));
shell.setLayout(new FillLayout());
} 给这里面加
shell.show();