Eclipse 3.6.2此处记录了此错误
https://bugs.eclipse.org/bugs/show_bug.cgi?id=358183
有一些建议的解决方法。第一个不适合我,但第二个没有。
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();
}
});
然而,当我实现它时,小部件认为用户已经改变了一些数据(状态改变)。这可能是因为上面的调用
combo.setText(text);
在我们的系统设置完成后,可以调用
org.eclipse.ui.forms.ManagedForm.isDirty()
每次用户退出表单时都会提示用户保存数据。
我对SWT或jFace一点也不熟悉。有谁能告诉我
由于
答案 0 :(得分:0)
仅设置Combo
的文字不会自动将ManagedForm
设置为脏。因此,您必须在组合中添加修改侦听器才能执行set dirty。
您可以在执行setText
之前从组合中删除修改侦听器,然后在setText
之后将其添加回来。这应该可以阻止设置脏标志。