How do I get my text to center vertically in a uicontrol textbox?
조회 수: 141(최근 30일)
표시 이전 댓글
I am creating a GUI programmatically and I have a panel that I am displaying text boxes. How do I get my text boxes to display the text in the center of the vertical dimension? There is a horizontalAlignment property that centers horizontally, but the vertical dual does not seem to exist.
hf = figure('Units','normalized',...
'Position',[0.2 0.2 0.6 0.7]);
hPanel = uipanel(hf, 'Position',[0.01 0.02 0.98 0.93]);
posPanel = [0.26 0.28 0.51 0.72];
subPanel = uipanel(hPanel,'Position',posPanel,'FontSize',11);
posTs = [0.2 0.005 0.12 0.08];
SampleTime = uicontrol(subPanel,'Style','text',...
'String','100.0s',...
'FontSize',11,...
'HorizontalAlignment','Center',...
'Units','normalized',...
'Position',posTs,...
'Background',[.8 .8 .8]);
댓글 수: 3
Jiri Hajek
2021년 7월 28일
A workaround that was sufficient for my needs is that the "Edit Field" component has the text vertically aligned to the center, while "Text Area" has the text vertically aligned to the top...
답변(1개)
Jan
2017년 3월 7일
You are right: There is no vertical alignment for uicontrol 's. You can create an (invisible) axes instead and use text(), which has the VerticalAlignment property.
댓글 수: 3
Rik
2021년 5월 5일
Thank you for the suggested edits. However, you should also edit the comments and the help text, as that doesn't match the code in your version. (you also moved the first comment to the help text)
참고 항목
범주
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!