2012-02-01 8 views
1

これはかなり簡単に実装できますが、標準の機能を使用する必要があります。 テキストフィールドにテキストを表示するにはツールチップが必要ですが、テキストフィールド内のテキストをフィールドに表示するには長い時間が必要です。テーブルとツリーは列のサイズを変更するときにこの機能を持っていますが、テキストフィールドでは何も似ていません。SWT/JFaceコントロールのテキストが大きすぎて表示することができない場合のテキストのコントロールのヒント

Eclipseでこの機能を検出できなかったため、標準機能ではないと思います。 私を間違っていると証明してください:)。

ありがとうございます。

答えて

3

「標準機能」とは何ですか? modifyListenerTextに追加すると、インスタンスが十分に(imo)標準になります。

は、ここでは、テーブルや木であり、正確に同じように、

import org.eclipse.swt.SWT; 
import org.eclipse.swt.events.ModifyEvent; 
import org.eclipse.swt.events.ModifyListener; 
import org.eclipse.swt.graphics.GC; 
import org.eclipse.swt.graphics.Point; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.widgets.Text; 


public class TextLabel { 
    public TextLabel() { 
     Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setLayout(new GridLayout()); 
     shell.setSize(200, 150); 
     shell.setText("Long Text content label"); 

     Text txtLong = new Text(shell, SWT.SINGLE | SWT.BORDER); 
     txtLong.addModifyListener(new ModifyListener() { 

      @Override 
      public void modifyText(ModifyEvent e) { 
       Text txtSource = (Text) e.getSource(); 
       Point size = (new GC(txtSource)).stringExtent(txtSource.getText()); 
       if(size.x > txtSource.getBounds().width - txtSource.getBorderWidth()) txtSource.setToolTipText(txtSource.getText()); 
       else txtSource.setToolTipText(null); 
      } 
     }); 

     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
     display.dispose(); 
    } 

    public static void main(String args[]) { 
     new TextLabel(); 
    } 
} 
+0

こんにちは、標準機能は、箱から出して意味私のアプローチです。私はおそらく、それは箱から実装されていると私はちょうどそれを活性化する必要がありますか何か。あなたのコードはcorectであり、働いています。 – Lori

+0

私はこの機能をアウトオブボックスに認識していません。 – Sorceror

+0

基本的には、テーブルやツリーを作成し、テキストがもう収まらないように1つの列のサイズを変更すると、コンポーネントがこれを提供することがわかります機能をそのまま使用できます。 – Lori

関連する問題