開發平臺是Fedora上的Eclipse RCP 3.4(它使用的是Gtk本地組件)。我需要避免換行。是否可以修改文本swt控件如何包裝單詞?
即:「Hello World」顯示爲案例N°1,但我需要案例N°2。
1|Hello | 2|Hello Wor|
|World | |ld |
有沒有簡單的解決方案?
我見過swt文本句柄是用OS.GTK_WRAP_WORD_CHAR
換行模式構建的。我想用像OS.GTK_WRAP_WORD
或OS.GTK_WRAP_NONE
這樣的常量測試行爲,但我不知道如何執行這個奇蹟?是否有可能以編程方式修改平臺特定的配置?
編輯1 - 有一個從我的一個同事的解決方案:
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();
}
}
}
}
的是,預期的結果。我正在尋找來自http://dev.eclipse.org的解決方案。