5

Text / Combo 変数に対してそのようなデコレータを有効にする基本的な方法 (カスタム API なし) は何でしょうか? ここに画像の説明を入力

4

2 に答える 2

11

これが私がそれをどうやってやったかです:

        //---> 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_ERRORforはFieldDecorationRegistry、エラー アイコンを設定します。

ここに画像の説明を入力

于 2013-05-30T09:00:48.563 に答える
5

JFace データバインディングは、無効な入力を自動的に装飾します。

 ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT);

これにより、コントロールがアイコンで装飾され、ツールチップ テキストが検証ステータスの説明に設定されます。あなたの場合、これらすべての変更リスナーを手動で処理する必要はありません。

于 2015-04-21T10:18:49.943 に答える