Text box (auto) size for proportional fonts

조회 수: 14 (최근 30일)
Charles
Charles 2011년 6월 13일
Hi,
I'm developing a GUI with plots that need annotations. I've been using the Static Text uicontrol and specifying its size and position like this:
position = [xpos ypos width height];
set(box_handle,'String',annotate_string);
set(box_handle,'Position',position);
set(box_handle,'Visible','on');
This places the text correctly, but since the font is proportional, sometimes my sizing heuristic (# chars * 1.3) fails.
If the box were to auto-size I'd be home free, but I see no way to do that. The only other alternative is to compute the width from a font table containing widths of all letters. But that's reinventing the wheel, and badly, since the information must be in Matlab already...
Thanks,
Charles

채택된 답변

Walter Roberson
Walter Roberson 2011년 6월 13일
After you set() the String as desired, get() the Extent property: the third element of that tells you the width that would be required to display the entire string. You can adjust your Position based upon that.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by