I want to put some text in a GUI, and I want to know the exact size of a uicontrol type 'text' !
I found several threads explaining that this can be done using the 'Extent' property of the 'text' object containing the same text, see example:
function form = tempfunc(txt,font,fontsize) if nargin <3 fontsize = 10; end if nargin < 2 font = 'courier'; end f = figure('Visible','off','Units','pixels'); u = uicontrol(f,'Style','text','Units','pixels','String',txt,'FontName',font,'FontSize',fontsize); textsize = get(u,'Extent'); textsize = textsize(3:4); close(f); form = figure('Units','pixels'); uicontrol(form,'Style','text','Units','pixels','String',txt,'FontName',font,'FontSize',fontsize,'Position',[5,5,textsize]); end
My problem is that this does not work. When I run above using tempfunc(repmat('A',14)); , I get the following window with a picture:

As you can see from the image, the height of the text extracted in the textsize variable is too small!
Please note that this is the result that I received when I started the program on my Windows computer on which Matlab R2014a is installed. Then I ran the same code on the Linux machine running Matlab R2013b, and on this machine I got the result that I wanted.
The GUI that I create should (hopefully) be able to run on any computer, but right now I'm really at a loss about how I should make a version that works on any machine, so please help me!
EDIT: I tried to run the same code on another computer running Windows 7 (this time Ultimate edition instead of my Enterprise version), which runs Matlab R2011b (instead of my R2014a), it still creates the wrong height of the text box, but on this time the text box was too high - see image:

EDIT2: I finally got R2014b, but unfortunately this did not help! I have a similar picture:

I also tried to understand if different resolution options for my screen had changed - they did not.
EDIT3:
I noticed that different fonts give different errors in height, for example. the default font (MS Sans Serif) gives the text field too high (and this error in height also grows as more lines are added). However, on Linux, I got the correct result for all the fonts I tried.
But in fact, I am most interested in the case of using a courier font, because for my purpose I need a monospace font.