![](/img/trans.png)
[英]How to Set the color of org.eclipse.swt.widgets.Text borders
[英]org.eclipse.swt.widgets.Text validation decorator in eclipse SWT
為Text / Combo變量啟用這樣的裝飾器的基本方法(沒有自定義API)是什么?
以下是我設法做到的方法:
//---> input
myPackage = new Text(grpConnection, SWT.BORDER);
myPackage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//---> input event
myPackage.addModifyListener(new ModifyListener(){
// decorator for UI warning
ControlDecoration decorator;
/*
* In this anonymous constructor we will initialize what needs to be initialized only once, namely the decorator.
*/
{
decorator = new ControlDecoration(myPackage, SWT.CENTER);
decorator.setDescriptionText("Not a valid package");
Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
decorator.setImage(image);
}
@Override
public void modifyText(ModifyEvent e) {
if (true) { // place your condition here
decorator.show();
}
else {
decorator.hide();
}
}
});
DEC_ERROR
的FieldDecorationRegistry
設置錯誤圖標。
JFace數據綁定將自動為您裝飾無效輸入:
ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT);
這將使用圖標修飾控件,並將工具提示文本設置為驗證狀態描述。 在您的情況下,您不必手動處理所有這些修改偵聽器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.