刚刚学这块,什么都不懂,下面的这段程序可调试的,请问大家为什么text.setSize(800,300);这句没有用,怎么修改text的长度和大小,就是宽度和高度。
package test1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class test5 {
private Shell _shell;
public Shell getShell() {
return _shell;
}
public void setShell(Shell shell) {
this._shell = shell;
}
public test5() {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
setShell(shell);
shell.setLayout(new RowLayout(SWT.HORIZONTAL));
shell.setText("Menu Demo");
Text text=new Text(shell,SWT.MULTI|SWT.BORDER| SWT.V_SCROLL);
text.setSize(800,300);
shell.setSize(500, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
test5 demo=new test5();
}
}
package test1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class test5 {
private Shell _shell;
public Shell getShell() {
return _shell;
}
public void setShell(Shell shell) {
this._shell = shell;
}
public test5() {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
setShell(shell);
shell.setLayout(new RowLayout(SWT.HORIZONTAL));
shell.setText("Menu Demo");
Text text=new Text(shell,SWT.MULTI|SWT.BORDER| SWT.V_SCROLL);
text.setSize(800,300);
shell.setSize(500, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
test5 demo=new test5();
}
}
------
差不多的..你查一下API就清楚了....API可是很有用的..
如果是想要在代码上进行修改,用text.setPreferSize()当然了,这个跟布局也有关系。有些布局是默认空间位置跟大小的。你可以把属性里面的布局那一栏选null(好久没碰了,应该是这个)