用java swt text显示字符串内容,但在text中 为什么格式是不对齐的呢?但在控制台上显示就是整齐的
importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;importorg.e...
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
public class myGui {
protected Shell shell;
private Text text;
public static void main(String[] args) {
try {
myGui window = new myGui();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(950, 800);
shell.setText("my Application");
text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
text.setBounds(50, 20, 776, 519);
String ss = "************************************************************\r\n"
+ "* *\r\n"
+ "* welecome my Gui *\r\n"
+ "* *\r\n"
+ "* Copyright by haha_xiao , 2014 *\r\n"
+ "* *\r\n"
+ "************************************************************\r\n";
text.setText(ss);
String rr = text.getText();
System.out.println(rr ); // 显示在控制台上的很整齐,但是在text中显示的,就不整齐,是什么原因呢
}
} 展开
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
public class myGui {
protected Shell shell;
private Text text;
public static void main(String[] args) {
try {
myGui window = new myGui();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(950, 800);
shell.setText("my Application");
text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
text.setBounds(50, 20, 776, 519);
String ss = "************************************************************\r\n"
+ "* *\r\n"
+ "* welecome my Gui *\r\n"
+ "* *\r\n"
+ "* Copyright by haha_xiao , 2014 *\r\n"
+ "* *\r\n"
+ "************************************************************\r\n";
text.setText(ss);
String rr = text.getText();
System.out.println(rr ); // 显示在控制台上的很整齐,但是在text中显示的,就不整齐,是什么原因呢
}
} 展开
2个回答
展开全部
图像化就是这样,比较恶心,如果你想要整齐的,先要重写图形化的格式方法,推荐二篇文件:
http://www.blogjava.net/dreamstone/archive/2007/08/06/134533.html
http://www.blogjava.net/zeyuphoenix/archive/2010/05/03/319976.html
http://www.blogjava.net/dreamstone/archive/2007/08/06/134533.html
http://www.blogjava.net/zeyuphoenix/archive/2010/05/03/319976.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询