Doug Null
Doug Null

Reputation: 8327

can't get Matlab uicontrol 'text' box to position at top of figure window

I want to display my 'text' at the top of the figure window, but at first the window is empty until I stretch it downward, and there is my text in the middle of the window.

The 'position' property is [left bottom width height] What does 'bottom' mean? Pixels from the bottom? I can't figure it out.

I've tried adjusting 'bottom' but can't get text at top of window.

UPDATE: Using 'position', [30 1 600 300] now shows text in middle of figure window, but I still want to know how to position at top of window.

figure('menu','none','toolbar','none',   'KeyPressFcn', @(src,evnt)parse_keypress(evnt,'press'), 'Name', 'COMMAND UI' );
txt = '';
txt = sprintf( '%s * COMMAND MENU * \n', txt );
txt = sprintf( '%s "B" breaks. \n', txt );
txt = sprintf( '%s "L" toggles Logitech_webcam_settings manual/auto\n', txt );
txt = sprintf( '%s "M" enables dynamic Disparity Map \n', txt );
txt = sprintf( '%s "Q"  quits \n', txt );
txt = sprintf( '%s "P" pauses \n', txt );
txt = sprintf( '%s "S" show proximity pixles \n', txt );
txt = sprintf( '%s "V" shows 2nd video window \n', txt );


uicontrol('Style','text','Position',[30 1 180 600],'String',txt,...
    'HorizontalAlignment','left');

Upvotes: 0

Views: 804

Answers (2)

ninehundred
ninehundred

Reputation: 241

You didn't specify the height when calling figure, so the standard size figure window is created and your text is positioned too high for the size of the figure generated, so it plots the text 'out of bounds'.

Either lower the height parameter of the text to something like

uicontrol('Style','text','Position',[40 1 180 400],'String',txt,...
'HorizontalAlignment','left');

or generate a figure with a height that is larger than your text field

FigHandle = figure('menu','none','toolbar','none',   'KeyPressFcn',    @(src,evnt)parse_keypress(evnt,'press'), 'Name', 'COMMAND UI' );
txt = '';
txt = sprintf( '%s * COMMAND MENU * \n', txt );
txt = sprintf( '%s "B" breaks. \n', txt );
txt = sprintf( '%s "L" toggles Logitech_webcam_settings manual/auto\n', txt );
txt = sprintf( '%s "M" enables dynamic Disparity Map \n', txt );
txt = sprintf( '%s "Q"  quits \n', txt ); 
txt = sprintf( '%s "P" pauses \n', txt );
txt = sprintf( '%s "S" show proximity pixles \n', txt );
txt = sprintf( '%s "V" shows 2nd video window \n', txt );


set(FigHandle, 'Position', [100, 100, 500 600]);

uicontrol('Style','text','Position',[30 1 180 600],'String',txt,...
'HorizontalAlignment','left');

Upvotes: 0

horchler
horchler

Reputation: 18484

You need to specify the position of your text relative to the size of your figure window. The default figure size is 560 pixels wide 420 pixels high. Or you can get it via:

hf = figure('menu','none',...
            'toolbar','none',...
            'KeyPressFcn', @(src,evnt)parse_keypress(evnt,'press'),...
            'Name','COMMAND UI');
figPosition = get(hf,'Position'); % hf.Position also

which returns (the first two values will probably different for you as they represent the position of the bottom left of the figure relative to the bottom left of your screen)

680   678   560   420

Then you can use this to specify the initial location of your text:

ht = uicontrol('Style','text',...
               'Position',[30 1 180 figPosition(4)],...
               'String',txt,...
               'HorizontalAlignment','left');

Of course, if you resize the height of your window, the text will move as it is positioned relative to the bottom left...

Upvotes: 1

Related Questions