Saritha
Saritha

Reputation: 181

how to find out if the string given will fit on a particular gwt label or not.

I am new to gwt and I am trying to check if the dynamic string document id that i am retrieving will will fit on the gwt label or not. Now I am checking for the number of characters and if the number exceeds 15 I am appending ... after 12 characters and displaying the actual id in the tooltip. I need to know how do i achieve this without calculating the number of characters. Please help

Upvotes: 0

Views: 103

Answers (1)

The width of a label does not only depend on the string size, but on the font used.

You could write you string in a temporary label attached to the dom and query the size using the method 'getClientWidth' of the element or gwtquery, and remove recursively the last character until you get the appropriate size.

In my opinion the easier way would be to use css and define a fixed width of your label and set the property overflow to hidden, so you see just the chars which fit in the label and you dont have to deal with a different string.

Upvotes: 1

Related Questions