Java TreeViewer SWT.RIGHT_TO_LEFT [英] Java TreeViewer SWT.RIGHT_TO_LEFT
问题描述
我正在使用一个具有两个TreeViewer
的Eclipse插件,其中一个具有参数SWT.RIGHT_TO_LEFT
.看起来像这样:
I work on a Eclipse Plugin which have two TreeViewer
, one of them with the parameter SWT.RIGHT_TO_LEFT
. This looks like this:
如您所见,树结构是从右到左绘制的,这就是我所需要的.但是,这是我的问题,文本也被反转了,但仅当字符串中包含特殊字符时才被反转.
PID.5.7
转换为7.5.PID
.
这是我创建TreeViewer
和文本的方法:
As you see the Tree Structure is drawn from right to left and that is what i need. But and here is my problem, the Text gets also inverted but only when special characters are in the string.
PID.5.7
is transformed to 7.5.PID
.
Here is how i create TreeViewer
and the Text:
xmlTreeOut = new TreeViewer(composite, SWT.RIGHT_TO_LEFT | SWT.DOUBLE_BUFFERED);
...
xmlTreeOut.getTree().addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
//loop over treeItems and for each
...
TextLayout textLayout = new TextLayout(Display.getDefault());
textLayout.setText(xmlName + xmlValue);
textLayout.draw(event.gc, root.getBounds().x + 2, root.getBounds().y + 1);
...
}
});
有人可以解决此问题吗?我想完全按照在TextLayout
中编写的字符串输入字符串.
Does anyone have a fix for this problem? I would like to have my String exactly as I write it in the TextLayout
.
我添加了提到的
textLayout.setOrientation(SWT.RIGHT_TO_LEFT);
现在我的输出是这样的:
Now my output is like this:
如您所见,它适用于PID.7.5之类的字符串,但是如果字符串之间用空格分隔,并且仅包含特殊字符,则该字符串与之相反. 像"MSH.1 |"变成"| MSH.1"
As you can see it worked for Strings like PID.7.5 but if there are Strings seperated with space and only containing special characters its inversed. Like "MSH.1 |" becomes "| MSH.1"
(删除了Style2,在TextLayout中仅使用一种样式)
(removed the Style2 and use only one style in TextLayout)
解决方案:
我现在测试我的String是否以不带a-z,A-Z的单词"开头,我只需在前面添加StyleColor = WHITE的"x"即可.这样,所有值都可以正确使用.
I test now if my String starts with a "word" which has no a-z, A-Z I simply add a "x" with StyleColor = WHITE in front. This way all values are displeyed correctly.
推荐答案
I haven't tested this, but the method TextLayout#setOrientation(int orientation)
looks like what you need:
设置接收器的方向,必须为
SWT.LEFT_TO_RIGHT
或SWT.RIGHT_TO_LEFT
之一.
只需将两个TreeViewer
都设置为SWT.LEFT_TO_RIGHT
(或者将右TreeViewer
的SWT.RIGHT_TO_LEFT
设置为SWT.RIGHT_TO_LEFT
,以将先前的从右向左转换?).
Just set it to SWT.LEFT_TO_RIGHT
for both TreeViewer
s (or maybe SWT.RIGHT_TO_LEFT
for the right TreeViewer
to invert the previous right-to-left ?).
这篇关于Java TreeViewer SWT.RIGHT_TO_LEFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!