[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] How to set width of Combo or Text to match its TextLimit

In adding Combo and Text controls to a Composite with a GridLayout, wanted each control's width to be able to accomodate up to it's TextLimit number of characters.

Found that calling setSize() on the control immediately after it was constructed seemed to have no effect.
What did work was calling setText() and passing a String that contained TextLimit number of a character that is of average size width (I used N's).
Got away with this, since the fields are immediately filled with values from a model, so users never sees the "NNNNNNN"s.


Still I wonder if this is the only way to do this in SWT??

Also I was setting arbitrary widths when calling setSize(), since I could find no way via the Font class to get the size of a String. If setSize() had worked planned to call Control.getFont() and then call something like awt's Font.getStringBounds() for the Font the Control was using. Is there a similar SWT api?