SWT(JFace)体验之体验之StyledText类类
有的时候Text需要实现这种那种的样式。先提供在不使用StyledText类的情况:
WrapLines.java
复制代码 代码如下:
package swt_jface.demo4;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class WrapLines {
Display display = new Display();
Shell shell = new Shell(display);
Text text1;
Text text2;
String line = "abcdefghijklmnopqrstuvwxyz0123456789";
private void init() {
text1 = new Text(shell, SWT.BORDER | SWT.MULTI);
//text.setTextLimit(12);
text1.setText(line);
text2 = new Text(shell, SWT.BORDER | SWT.WRAP);
text2.setText(line);
}
public WrapLines() {
shell.setLayout(new GridLayout(2, true));
(new Label(shell, SWT.NULL)).setText("SWT.BORDER |SWT.MUTLI");
(new Label(shell, SWT.NULL)).setText("SWT.BORDER |SWT.WRAP");
init();
GridData gridData = new GridData(GridData.FILL_BOTH);
text1.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_BOTH);
text2.setLayoutData(gridData);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new WrapLines();
}
}
RemarksText.java
复制代码 代码如下:
package swt_jface.demo4;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
评论0
最新资源