无法将 Matlab uicontrol 'text' 框定位在图的顶部 window
can't get Matlab uicontrol 'text' box to position at top of figure window
我想把我的'text'显示在图的最上面window,但是一开始window是空的,直到我把它往下拉,然后我的文字在window.
中间
'position'属性就是[左下宽高]
'bottom' 是什么意思?从底部开始的像素?想不通了。
我试过调整 'bottom' 但无法在 window 顶部获取文本。
更新:
使用 'position'、[30 1 600 300]
现在在图 window 中间显示文本,但我仍然想知道如何定位在 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');
您需要指定文本相对于图形大小的位置 window。默认图形大小为 560 像素宽 420 像素高。或者您可以通过以下方式获取:
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(前两个值对您来说可能会有所不同,因为它们代表图形左下角相对于屏幕左下角的位置)
680 678 560 420
然后您可以使用它来指定文本的初始位置:
ht = uicontrol('Style','text',...
'Position',[30 1 180 figPosition(4)],...
'String',txt,...
'HorizontalAlignment','left');
当然,如果您调整 window 的高度,文本将移动,因为它相对于左下角的位置...
您在调用图形时没有指定高度,因此创建了标准尺寸的图形 window 并且您的文本位置对于生成的图形大小来说太高了,因此它绘制了文本 'out of bounds'。
要么将文本的高度参数降低到
uicontrol('Style','text','Position',[40 1 180 400],'String',txt,...
'HorizontalAlignment','left');
或者生成一个高度大于文本字段的图形
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');
我想把我的'text'显示在图的最上面window,但是一开始window是空的,直到我把它往下拉,然后我的文字在window.
中间'position'属性就是[左下宽高] 'bottom' 是什么意思?从底部开始的像素?想不通了。
我试过调整 'bottom' 但无法在 window 顶部获取文本。
更新: 使用 'position'、[30 1 600 300] 现在在图 window 中间显示文本,但我仍然想知道如何定位在 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');
您需要指定文本相对于图形大小的位置 window。默认图形大小为 560 像素宽 420 像素高。或者您可以通过以下方式获取:
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(前两个值对您来说可能会有所不同,因为它们代表图形左下角相对于屏幕左下角的位置)
680 678 560 420
然后您可以使用它来指定文本的初始位置:
ht = uicontrol('Style','text',...
'Position',[30 1 180 figPosition(4)],...
'String',txt,...
'HorizontalAlignment','left');
当然,如果您调整 window 的高度,文本将移动,因为它相对于左下角的位置...
您在调用图形时没有指定高度,因此创建了标准尺寸的图形 window 并且您的文本位置对于生成的图形大小来说太高了,因此它绘制了文本 'out of bounds'。
要么将文本的高度参数降低到
uicontrol('Style','text','Position',[40 1 180 400],'String',txt,...
'HorizontalAlignment','left');
或者生成一个高度大于文本字段的图形
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');