swt/jface做了一个窗口,上面放几个控件,可每次运行时都不显示控件,要将窗口全屏显示后才会出现。?
程序源代码如下:importorg.eclipse.swt.SWT;importorg.eclipse.swt.custom.ViewForm;importorg.ecl...
程序源代码如下:
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
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.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class SimpleEditor2 {
public static void main(String[] args){
Display display=Display.getDefault();
Shell shell=new Shell();
shell.setText("hello");
shell.setBounds(34,54,300,400);
shell.open();
shell.layout();
shell.setLayout(new FillLayout());
final ViewForm viewForm=new ViewForm(shell,SWT.NONE);
viewForm.setLayout(new FillLayout());
final Text text=new Text(viewForm,SWT.BORDER|SWT.V_SCROLL);
viewForm.setContent(text);
CoolBar coolBar=new CoolBar(viewForm,SWT.NONE);
{
ToolBar toolBar=new ToolBar(coolBar,SWT.NONE);
ToolItem getItem=new ToolItem(toolBar,SWT.PUSH);
getItem.setText("get");
getItem.setImage(new Image(display,"icons/selectall.gif"));
ToolItem clearItem=new ToolItem(toolBar,SWT.PUSH);
clearItem.setText("clear");
clearItem.setImage(new Image(display,"icons/remove.gif"));
CoolItem coolItem=new CoolItem(coolBar,SWT.NONE);
coolItem.setControl(toolBar);
toolBar.pack();
Point size=toolBar.getSize();
coolItem.setSize(size);
coolItem.setMinimumSize(size);
}
Combo combo=new Combo(coolBar,SWT.BORDER);
combo.add("http://www.sdfi.edu.cn");
combo.select(0);
CoolItem coolItem=new CoolItem(coolBar,SWT.NONE);
coolItem.setControl(combo);
combo.pack();
Point size=combo.getSize();
coolItem.setSize(size);
coolItem.setMinimumSize(size);
viewForm.setTopLeft(coolBar);
coolBar.addControlListener(new ControlAdapter(){
public void controlResized(ControlEvent e){
viewForm.layout();
}
});
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
} 展开
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
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.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class SimpleEditor2 {
public static void main(String[] args){
Display display=Display.getDefault();
Shell shell=new Shell();
shell.setText("hello");
shell.setBounds(34,54,300,400);
shell.open();
shell.layout();
shell.setLayout(new FillLayout());
final ViewForm viewForm=new ViewForm(shell,SWT.NONE);
viewForm.setLayout(new FillLayout());
final Text text=new Text(viewForm,SWT.BORDER|SWT.V_SCROLL);
viewForm.setContent(text);
CoolBar coolBar=new CoolBar(viewForm,SWT.NONE);
{
ToolBar toolBar=new ToolBar(coolBar,SWT.NONE);
ToolItem getItem=new ToolItem(toolBar,SWT.PUSH);
getItem.setText("get");
getItem.setImage(new Image(display,"icons/selectall.gif"));
ToolItem clearItem=new ToolItem(toolBar,SWT.PUSH);
clearItem.setText("clear");
clearItem.setImage(new Image(display,"icons/remove.gif"));
CoolItem coolItem=new CoolItem(coolBar,SWT.NONE);
coolItem.setControl(toolBar);
toolBar.pack();
Point size=toolBar.getSize();
coolItem.setSize(size);
coolItem.setMinimumSize(size);
}
Combo combo=new Combo(coolBar,SWT.BORDER);
combo.add("http://www.sdfi.edu.cn");
combo.select(0);
CoolItem coolItem=new CoolItem(coolBar,SWT.NONE);
coolItem.setControl(combo);
combo.pack();
Point size=combo.getSize();
coolItem.setSize(size);
coolItem.setMinimumSize(size);
viewForm.setTopLeft(coolBar);
coolBar.addControlListener(new ControlAdapter(){
public void controlResized(ControlEvent e){
viewForm.layout();
}
});
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询