亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > Java > 正文

SWT(JFace)體驗之StyledText類

2020-01-31 16:51:32
字體:
來源:轉載
供稿:網友
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 |/nSWT.MUTLI");
(new Label(shell, SWT.NULL)).setText("SWT.BORDER |/nSWT.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;
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 RemarksText {

Display display = new Display();
Shell shell = new Shell(display);

Text text;
public RemarksText() {

shell.setLayout(new GridLayout(1, false));
(new Label(shell, SWT.NULL)).setText("Remarks:");
text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
text.setText("123456789");
text.setLayoutData(new GridData(GridData.FILL_BOTH));
System.out.println("getText: " + text.getText(1, 6));
char[] chars = text.getLineDelimiter().toCharArray();
for (int i = 0; i < chars.length; i++) {
System.out.println("Line delimiter #" + i + ": " + Integer.toHexString(chars[i]) );
}
text.getOrientation();
System.out.println("Number of chars: " + text.getCharCount());
System.out.println("Tabs: " + text.getTabs());
text.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
if(e.end == e.start) {
if( e.character == ' ' && (e.stateMask & SWT.CTRL) != 0 ) {
if(text.getText(e.end-1, e.end-1).equals("V")) {
e.text = "erifyListener";
}else{
e.doit = false;
}
}
}
}
});
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
System.out.println("New character count: " + text.getCharCount());
}
});
// text.append("a");

text.setSelection(1, 4);
System.out.println("getSelection:/t" + text.getSelection());
System.out.println("getSelectionCount:/t" + text.getSelectionCount());
System.out.println("getSelectionText:/t" + text.getSelectionText());
//text.insert("ABC");
// shell.pack();
shell.setSize(300, 150);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new RemarksText();
}
}

再比如密碼框:
UserPassword.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 UserPassword {

Display display = new Display();
Shell shell = new Shell(display);

Text textUser;
Text textPassword;
private void init() {

(new Label(shell, SWT.NULL)).setText("User name: ");
textUser = new Text(shell, SWT.SINGLE | SWT.BORDER);
textUser.setText("default_user");
textUser.setTextLimit(16);
(new Label(shell, SWT.NULL)).setText("Password: ");
textPassword = new Text(shell, SWT.SINGLE | SWT.BORDER);
System.out.println(textPassword.getEchoChar());
textPassword.setEchoChar('*');
}

public UserPassword() {

shell.setLayout(new GridLayout(2, false));
init();

textUser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new UserPassword();
}
}

下面演示使用StyledText類進行修飾Text的幾個例子:

HighlightOddLine.java
復制代碼 代碼如下:

package swt_jface.demo4;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.LineBackgroundEvent;
import org.eclipse.swt.custom.LineBackgroundListener;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class HighlightOddLine {

Display display = new Display();
Shell shell = new Shell(display);

StyledText styledText;

public HighlightOddLine() {

shell.setLayout(new GridLayout());
styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
styledText.setLayoutData(new GridData(GridData.FILL_BOTH));
styledText.addLineBackgroundListener(new LineBackgroundListener() {
public void lineGetBackground(LineBackgroundEvent event) {
if(styledText.getLineAtOffset(event.lineOffset) % 2 == 1)
event.lineBackground = shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
}
});

styledText.setText("Line 0/r/nLine 1/r/nLine 2/r/nLine 3/r/nLine 4/r/nLine 5/r/nLine 6");
shell.setSize(300, 150);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new HighlightOddLine();
}
}

SetLineBackground.java
復制代碼 代碼如下:

package swt_jface.demo4;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SetLineBackground {

Display display = new Display();
Shell shell = new Shell(display);

StyledText styledText;
public SetLineBackground() {
shell.setLayout(new GridLayout());
styledText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
styledText.setLayoutData(new GridData(GridData.FILL_BOTH));
Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL);
styledText.setFont(font);
styledText.setText("abcdefg/r/nhijklmn");
StyleRange styleRange1 = new StyleRange();
styleRange1.start = 2;
styleRange1.length = 3;
styleRange1.foreground = shell.getDisplay().getSystemColor(SWT.COLOR_BLUE);
styleRange1.background = shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
styleRange1.fontStyle = SWT.BOLD;

styledText.setStyleRange(styleRange1);
styledText.setLineBackground(0, 1, shell.getDisplay().getSystemColor(SWT.COLOR_GREEN));
styledText.setLineBackground(1, 1, shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW));

shell.setSize(300, 120);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

public static void main(String[] args) {
new SetLineBackground();
}
}

SearchStyleText.java
復制代碼 代碼如下:

package swt_jface.demo4;
import java.util.LinkedList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.LineStyleEvent;
import org.eclipse.swt.custom.LineStyleListener;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class SearchStyleText {

Display display = new Display();
Shell shell = new Shell(display);
StyledText styledText;
Text keywordText;
Button button;

String keyword;

public SearchStyleText() {

shell.setLayout(new GridLayout(2, false));
styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 2;
styledText.setLayoutData(gridData);
keywordText = new Text(shell, SWT.SINGLE | SWT.BORDER);
keywordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL);
styledText.setFont(font);
button = new Button(shell, SWT.PUSH);
button.setText("Search");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
keyword = keywordText.getText();
styledText.redraw();
}
});

styledText.addLineStyleListener(new LineStyleListener() {
public void lineGetStyle(LineStyleEvent event) {
if(keyword == null || keyword.length() == 0) {
event.styles = new StyleRange[0];
return;
}
String line = event.lineText;
int cursor = -1;
LinkedList list = new LinkedList();
while( (cursor = line.indexOf(keyword, cursor+1)) >= 0) {
list.add(getHighlightStyle(event.lineOffset+cursor, keyword.length()));
}
event.styles = (StyleRange[]) list.toArray(new StyleRange[list.size()]);
}
});

keyword = "SW";
styledText.setText("AWT, SWING /r/nSWT & JFACE");

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

private StyleRange getHighlightStyle(int startOffset, int length) {

StyleRange styleRange = new StyleRange();
styleRange.start = startOffset;
styleRange.length = length;
styleRange.background = shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
return styleRange;
}
public static void main(String[] args) {
new SearchStyleText();
}
}

SampleStyledText.java
復制代碼 代碼如下:

package swt_jface.demo4;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SampleStyledText {

Display display = new Display();
Shell shell = new Shell(display);
StyledText styledText;
public SampleStyledText() {

shell.setLayout(new GridLayout());
styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
styledText.setLayoutData(new GridData(GridData.FILL_BOTH));
Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL);
styledText.setFont(font);
styledText.setText("123456789/r/nABCDEFGHI");

StyleRange styleRange1 = new StyleRange();
styleRange1.start = 2;
styleRange1.length = 16;
styleRange1.foreground = shell.getDisplay().getSystemColor(SWT.COLOR_BLUE);
styleRange1.background = shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
styleRange1.fontStyle = SWT.BOLD;

StyleRange styleRange2 = new StyleRange();
styleRange2.start = 14;
styleRange2.length = 3;
styleRange2.fontStyle = SWT.NORMAL;
styleRange2.foreground = shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
styleRange2.background = shell.getDisplay().getSystemColor(SWT.COLOR_BLUE);

// styledText.setStyleRange(styleRange1);
// styledText.setStyleRange(styleRange2);
//styledText.setStyleRanges(new StyleRange[]{styleRange1, styleRange2});
//styledText.setStyleRanges(new StyleRange[]{styleRange2, styleRange1});
//styledText.setLineBackground(1, 1, shell.getDisplay().getSystemColor(SWT.COLOR_GRAY));
// styledText.setSelection(4);
// System.out.println(printStyleRanges(styledText.getStyleRanges()) );
// styledText.insert("000");

System.out.println(printStyleRanges(styledText.getStyleRanges()) );
// styledText.setStyleRanges(new StyleRange[]{styleRange1});
// System.out.println(printStyleRanges(styledText.getStyleRanges()) );

//shell.pack();
shell.setSize(300, 120);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

private String printStyleRanges(StyleRange[] styleRanges) {
if(styleRanges == null)
return "null";
else if(styleRanges.length == 0)
return "[]";
StringBuffer sb = new StringBuffer();
for(int i=0; i<styleRanges.length; i++) {
sb.append(styleRanges[i] + "/n");
}
return sb.toString();
}
public static void main(String[] args) {
new SampleStyledText();
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
8x拔播拔播x8国产精品| 亚洲欧美国产一区二区三区| 日本一本a高清免费不卡| 少妇精69xxtheporn| 欧美日韩一区二区三区| 国产精品女主播| 久久影视电视剧凤归四时歌| 日韩精品视频在线观看网址| 日韩欧美精品中文字幕| 91国产美女视频| x99av成人免费| 国产在线播放91| 精品视频在线播放免| 亚洲wwwav| 午夜精品一区二区三区在线视| 欧美精品在线免费观看| 亚洲欧美中文在线视频| 久久精品一偷一偷国产| 91精品国产91久久久久| 成人激情黄色网| 久久成人精品电影| 欧美午夜精品在线| 亚洲一区二区三区久久| 日韩免费在线电影| 成人有码视频在线播放| 色综合老司机第九色激情| 欧美日韩午夜视频在线观看| 国产精品久久77777| 92看片淫黄大片看国产片| 亚洲全黄一级网站| 国产91精品黑色丝袜高跟鞋| 国内精品小视频在线观看| 91精品国产91久久久久久最新| 一区二区三区 在线观看视| 97成人精品视频在线观看| 国产suv精品一区二区三区88区| 欧美在线视频一区二区| 亚洲精品美女免费| 日韩精品视频三区| 国产成人涩涩涩视频在线观看| 日韩福利视频在线观看| 亚洲精品乱码久久久久久按摩观| 亚洲精品美女久久久久| 国产精品一区二区三| 亚洲福利视频免费观看| 欧美精品18videos性欧| 亚洲精品久久久久国产| 欧美成人自拍视频| 一本色道久久综合狠狠躁篇怎么玩| 国产91热爆ts人妖在线| 神马国产精品影院av| 国产精品第一第二| 久久亚洲成人精品| 91久久精品国产91久久| 亚洲国产欧美日韩精品| 精品无人国产偷自产在线| 狠狠躁夜夜躁人人爽超碰91| 国产视频欧美视频| 亚洲在线观看视频网站| 国产成人综合精品在线| 亚洲人成在线电影| 97色在线观看免费视频| 久久精品国产v日韩v亚洲| 亚洲精品国产精品国自产在线| 少妇久久久久久| 日韩欧美亚洲综合| 隔壁老王国产在线精品| 日韩精品极品视频免费观看| 伊人久久大香线蕉av一区二区| 欧美成人午夜激情在线| 日韩中文字幕在线看| 久久久欧美精品| 亚洲自拍偷拍在线| 岛国av在线不卡| 中文字幕久久久| 色偷偷888欧美精品久久久| 亚洲欧美国产视频| 欧美日韩激情视频8区| 国产视频精品免费播放| 国产日本欧美在线观看| 亚洲国产中文字幕在线观看| 日韩福利视频在线观看| 国产午夜一区二区| yw.139尤物在线精品视频| 国产精品大片wwwwww| 亚洲最大福利网站| 午夜免费在线观看精品视频| 国产欧美一区二区白浆黑人| www.国产一区| 欧美精品xxx| 一区二区三区四区视频| 伊人伊成久久人综合网站| 美日韩精品免费观看视频| 国产成人精品一区二区| 国产欧美va欧美va香蕉在| 久久99久久亚洲国产| 91国自产精品中文字幕亚洲| 欧美日本精品在线| 亚洲欧美国产另类| 91精品在线国产| 欧美老女人xx| 国产女同一区二区| 亚洲视频网站在线观看| 国产精品igao视频| 亚洲成人av在线| 91国内揄拍国内精品对白| 茄子视频成人在线| 国产日韩欧美夫妻视频在线观看| 国产视频自拍一区| 日韩影视在线观看| 2025国产精品视频| 91免费看片在线| 亚洲综合在线播放| 精品视频在线观看日韩| 精品久久久香蕉免费精品视频| 日韩在线观看免费高清| 欧美性xxxx| 亚洲电影成人av99爱色| 国产精品久久久| 中文字幕精品影院| 精品中文字幕视频| 伊人伊人伊人久久| 91高清免费视频| 欧亚精品中文字幕| 亚洲无线码在线一区观看| 国产精品免费一区二区三区都可以| 国产精品欧美一区二区三区奶水| 日韩精品免费在线视频观看| 久久久久久亚洲精品| 亚洲国产精品久久久久秋霞蜜臀| 亚洲综合av影视| 中文字幕精品www乱入免费视频| 日韩在线观看精品| 不卡av电影在线观看| 免费97视频在线精品国自产拍| 亚洲在线视频观看| 久久久久一本一区二区青青蜜月| 欧美孕妇孕交黑巨大网站| 国产一区二区三区高清在线观看| 精品国产31久久久久久| 午夜免费久久久久| 九色精品美女在线| 成人444kkkk在线观看| 日韩最新中文字幕电影免费看| 中文字幕自拍vr一区二区三区| 91高清视频免费| 国产美女高潮久久白浆| 91久久国产精品91久久性色| 国产精品 欧美在线| 日韩av大片在线| 国产精品成人va在线观看| 午夜精品久久久久久99热| 成人网在线免费看| 色一情一乱一区二区| 亚洲欧洲日韩国产| 亚洲午夜国产成人av电影男同| 亚洲女性裸体视频| 久久国内精品一国内精品| 中文字幕日韩欧美精品在线观看| 国产精品高清免费在线观看| 亚洲国产毛片完整版| 激情久久av一区av二区av三区| 国产亚洲综合久久| 欧美激情在线狂野欧美精品|