Java 修复了Eclipse3.6.2中显示右对齐组合文本的错误
Eclipse3.6.2在这里记录了这个bug 有几个建议的解决办法。第一个对我不起作用,但第二个对我起作用Java 修复了Eclipse3.6.2中显示右对齐组合文本的错误,java,eclipse,swt,jface,Java,Eclipse,Swt,Jface,Eclipse3.6.2在这里记录了这个bug 有几个建议的解决办法。第一个对我不起作用,但第二个对我起作用 combo.addListener(SWT.Resize, new Listener() { @Override public void handleEvent(final Event e) { //We need the original text, not the displayed substring which w
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();
}
});
我们的系统建立后,需要
org.eclipse.ui.forms.ManagedForm.isDirty()
这会在用户每次退出表单时提示用户保存数据
我对SWT或jFace一点也不熟悉。有人能告诉我吗
谢谢仅设置
组合的文本
不会自动将管理表单
设置为脏的。因此,您必须向组合添加一个modify listener才能进行设置
您可以在执行
setText
之前从组合中删除modify listener,然后将其添加回setText
之后。这将阻止设置脏标志。必须添加一个修改侦听器才能获取对文本的更改。这在哪里发生?您可以暂时删除侦听器。谢谢。我确实在代码中看到了这个组合。addModifyListener(modifyListener);我在setText调用之前删除了它,然后添加了它。这似乎奏效了。那么是修改侦听器设置了脏标志?非常感谢您的帮助。关于修改侦听器,您是对的。我已经按照建议做了,它正在发挥作用。非常感谢。
org.eclipse.ui.forms.ManagedForm.isDirty()