在text中输入一些文字后,移动鼠标选中一些字,如何只改变我选中的字的字体呢?
int start = text.getSelection().x;
int end = text.getSelection().y;
text.setSelection(start, end);
这样选中了字,问题是怎么只改变选中的字的字体?
int start = text.getSelection().x;
int end = text.getSelection().y;
text.setSelection(start, end);
这样选中了字,问题是怎么只改变选中的字的字体?
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final StyledText text = new StyledText(shell, SWT.BORDER);
text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
text.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) {
int start = text.getSelection().x;
int end = text.getSelection().y;
StyleRange style3 = new StyleRange();
style3.start = start;
style3.length = end - start;
style3.background = display.getSystemColor(SWT.COLOR_BLUE);
text.setStyleRange(style3); } }); shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/*Font(String name,
int style,
int size)
name - 字体名称。可以是字体外观名称或字体系列名称,并且可表示此 GraphicsEnvironment 中找到的逻辑字体或物理字体。逻辑字体的系列名称有:Dialog、DialogInput、Monospaced、Serif 或 SansSerif。预定义 String 常量是为所有这些名称(如 DIALOG)而存在。如果 name 为 null,则将新 Font 的逻辑字体名称(由 getName() 返回)设置为 "Default"。
style - Font 的样式常量。样式参数是整数位掩码,可以为 PLAIN,或 BOLD 和 ITALIC 的按位或(例如,ITALIC 或 BOLD|ITALIC)。如果样式参数不符合任何一个期望的整数位掩码,则将样式设置为 PLAIN。
size - Font 的磅值大小*/
你可以到这上面看看
http://www.eclipse.org/swt/
-----------------------------------------------
Quietly through .....