Java TreeViewer SWT.RIGHT_TO_LEFT [英] Java TreeViewer SWT.RIGHT_TO_LEFT

查看:69
本文介绍了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_RIGHTSWT.RIGHT_TO_LEFT之一.

只需将两个TreeViewer都设置为SWT.LEFT_TO_RIGHT(或者将右TreeViewerSWT.RIGHT_TO_LEFT设置为SWT.RIGHT_TO_LEFT,以将先前的从右向左转换?).

Just set it to SWT.LEFT_TO_RIGHT for both TreeViewers (or maybe SWT.RIGHT_TO_LEFT for the right TreeViewer to invert the previous right-to-left ?).

这篇关于Java TreeViewer SWT.RIGHT_TO_LEFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆