首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修正了Eclipse3.6.2错误,它显示Combo文本右对齐

修正了Eclipse3.6.2错误,它显示Combo文本右对齐
EN

Stack Overflow用户
提问于 2017-01-21 16:48:31
回答 1查看 125关注 0票数 0

Eclipse3.6.2这里记录了这个错误

bug.cgi?id=358183

有几个建议的解决办法。第一个不是为我工作,而是第二个为我工作。

代码语言:javascript
复制
   combo.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(final Event e) {
            //We need the original text, not the displayed substring which would return methods such as combo.getText() or combo.getItem(combo.getSelectionIndex())   
            String text = combo.getItem((int) combo.getData("selectionIndex"));
            //reset text limit
            combo.setTextLimit(text.length());
            GC gc = new GC(combo);
            //exact dimensions of selected text            
            int textWidth = gc.stringExtent(text).x;
            int magicConst = 14;
            int comboWidth = combo.getClientArea().width - magicConst;
            //In case the text is wider then the area on which it's displayed, we need to set a textLimit
            if (textWidth > comboWidth) {
                //find text limit - first we set it according to average char width of our text
                int averageCharWidth = textWidth / text.length();
                int tempLimit = comboWidth / averageCharWidth;
                //sometimes on resize it can happen that computed tempLimit is greater than text length
                if (tempLimit >= text.length()) {
                    tempLimit = text.length() - 1;
                }
                //then we fine-tune the limit - it must be as precise as possible    
                while (tempLimit > 0 && (comboWidth < gc.stringExtent(text.substring(0, tempLimit + 1)).x)) {
                    tempLimit--;
                }
                //textLimit must not be zero
                if (tempLimit == 0) {
                    tempLimit++;
                }
                combo.setTextLimit(tempLimit);
            }
            combo.setText(text);
            gc.dispose();
        }
    });

然而,当我实现这一点时,小部件认为用户已经更改了一些数据(状态更改)。这可能是因为上面的调用

代码语言:javascript
复制
combo.setText(text);

当我们的系统建立时,有一个呼叫

代码语言:javascript
复制
org.eclipse.ui.forms.ManagedForm.isDirty()

这样,每次用户退出表单时,都会向用户发出一个提示,以保存数据。

我对SWT或jFace一点也不熟悉。有人能告诉我吗

  1. 还有其他方法可以绕过Eclipse3.6bug吗?
  2. 如果没有,是否有一种方法可以清除组合框的脏状态,这样用户就不会被提示保存?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-22 08:37:06

仅仅设置Combo的文本不会自动将ManagedForm设置为脏。因此,您必须向组合体中添加一个修改监听器,以便进行set脏操作。

您可以在执行setText之前从组合框中删除修改监听器,然后将其添加到setText之后。这将阻止设置脏标志。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41781929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档