我是 gwt 的新手,我正在尝试检查我正在检索的动态字符串文档 ID 是否适合 gwt 标签。现在我正在检查字符数,如果数字超过 15,我将在 12 个字符之后附加 ... 并在工具提示中显示实际 id。我需要知道如何在不计算字符数的情况下实现这一点。请帮忙
问问题
81 次
1 回答
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.
于 2012-11-21T08:38:04.497 回答