1

I have a gwt button that has a fixed size. I want to present a text on it, and if that text exceeds the button length, I need to cut it short and put "..." in the end. I use the following code now:

if(name.length() > 11){
    //limiting the size of the text presented on the button
    name = name.substring(0,10)+"...";
}

I have a list of such buttons, and this approach causes that not all button's text have the same size.

The problem is, for example, that 10 chars of "!" are much shorter than 10 chars of "A".

Can anyone help me with a way to solve this issue?

Thanks!

4

2 に答える 2

3

速い答え。HTML5/CSS3 プロパティを使用してみてください。まさにそれを行います:

http://www.w3schools.com/cssref/css3_pr_text-overflow.asp

非 CSS3 ブラウザーでこれを行う必要がある場合は、ある種の偽物を作成する必要があります。たぶん、overflow-hidden を使用してボタンの div コンテンツを設定し、右に浮動 "..." を配置します。でもそれ以上に難しい…

于 2012-05-14T10:55:02.817 に答える
0

これらすべてのボタンにスタイルクラスを追加して、サイズを修正できます。次のようになります。

まず、スタイル クラスを各ボタンに追加します。

    Button button = new Button();
    button.addStyleName("buttonSizeStandard");

次に、css ファイルに一致するスタイルを追加します。

    .buttonSizeStandard{ 
         width: 200px;      //change 200 to whatever 
    }
于 2012-05-14T10:46:20.427 に答える