有没有可能修改文本swt小部件包装单词的方式? [英] Is it possible to modify how Text swt widget wrap word?
问题描述
即:Hello World显示为案例N°1,但我需要案例N°2。
1 |你好| 2 | Hello Wor |
| World | | ld |
有没有简单的解决方案?
我已经看到swt文本句柄是用 OS.GTK_WRAP_WORD_CHAR
wrap模式构建的。我想用像 OS.GTK_WRAP_WORD
或 OS.GTK_WRAP_NONE
这样的常量来测试行为,但我不知道如何履行这个奇迹?是否有可能以编程方式修改平台特定的配置?
编辑1 - 我的一位同事有一个解决方案:
import org.eclipse.swt.SWT;
导入org.eclipse.swt.internal.gtk.OS;
import org.eclipse.swt.layout。*;
导入org.eclipse.swt.widgets。*;
public class SampleGrabExcess {
public static void main(String [] args){
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
shell.setSize(70,70);
GridData gridData = new GridData();
文本addressText = new Text(shell,SWT.BORDER | SWT.MULTI){
@Override
protected void checkSubclass(){}
$ b $ @覆盖
protected void checkWidget(){
OS.gtk_text_view_set_wrap_mode(handle,1);
super.checkWidget();
}
};
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
addressText.setLayoutData(gridData);
addressText.setText(Hello World。);
shell.open(); $!
$ b while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
}
}
结果是预期的。我正在寻找来自 http://dev.eclipse.org 的解决方案。
不,我不明白你能做到这一点。
您可以将模式设置为OS.GTK_WRAP_WORD和OS.GTK_WRAP_NONE不会让您获得所需的行为,因为第一个单词在单词之间断开,就像OS.GTK_WRAP_WORD_CHAR一样,第二个单词也不会断行。您正在寻找的模式是GTK_WRAP_CHAR。但是,一个常量如OS.GTK_WRAP_CHAR甚至没有在 org.eclipse.swt.internal.gtk.OS 表明SWT的创造者可能反对允许这种行为,即使在理论上也是如此。
The development platform is an Eclipse RCP 3.4 on Fedora (It's using Gtk native component). I need to avoid word wrapping.
i.e.: "Hello World" is displayed as case N°1 but I need the case N°2.
1|Hello | 2|Hello Wor|
|World | |ld |
Is there a simple solution ?
I've seen that swt Text handle is build with OS.GTK_WRAP_WORD_CHAR
wrap mode. I would like to test the behaviour with constant like OS.GTK_WRAP_WORD
or OS.GTK_WRAP_NONE
but I don't know how to perform this miracle ? Is it possible to modify platform specific configuration programmatically ?
EDIT 1 - There is a solution from one of my colleagues:
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.gtk.OS;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class SampleGrabExcess {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
shell.setSize(70, 70);
GridData gridData = new GridData();
Text addressText = new Text(shell, SWT.BORDER | SWT.MULTI) {
@Override
protected void checkSubclass() {}
@Override
protected void checkWidget() {
OS.gtk_text_view_set_wrap_mode(handle, 1);
super.checkWidget();
}
};
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
addressText.setLayoutData(gridData);
addressText.setText("Hello World.");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
The result is that expected. I'm looking for a solution from http://dev.eclipse.org.
No, I don't see how you could do that.
Btw, even if you could, setting the mode to OS.GTK_WRAP_WORD and OS.GTK_WRAP_NONE wouldn't get you the desired behaviour, since the first one breaks line in between words, just like OS.GTK_WRAP_WORD_CHAR, and the second one doesn't break lines at all. The mode you're looking for is GTK_WRAP_CHAR. However, the fact that a constant such as OS.GTK_WRAP_CHAR isn't even declared in org.eclipse.swt.internal.gtk.OS indicates that the creators of SWT were probably against allowing such behaviour, even in theory.
这篇关于有没有可能修改文本swt小部件包装单词的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!