center text in app designer

16 次查看(过去 30 天)
piero
piero 2023-6-13
编辑: dpb 2023-6-15
hi, it' possibile to center vertically "HALLO" in field?
  2 个评论
dpb
dpb 2023-6-13
Yeah, just klick on the center icon in the 'Horizontal Alignment" property for the Text section you've got in the attached figure.
Don't know if it was intended or not, but English spelling of the greeting is "Hello" instead of "Hallo" -- but it may be something else entirely... :)
piero
piero 2023-6-13
:P
i want alignement verticaly not horizontaly

请先登录,再进行评论。

回答(2 个)

Voss
Voss 2023-6-13
移动:Matt J 2023-6-14
Per the documentation, "Text areas are UI components for entering multiple lines of text." Therefore, it makes sense that they don't have a VerticalAlignment property. However, label components do have a VerticalAlignment property, so maybe use a label instead of a text area.
  7 个评论
dpb
dpb 2023-6-15
Well, as my example shows, you can set the background color so the area shows up white as the textarea,but while the textarea has the "box" property and lacks vertical alignment, the label has vertical alignment choices but no outline box.
I tried laying an axes over it to use the box feature there but wasn't successful in being able to make it work as desired; some very bizarre things happen when try to do it that I don't fully understand with respect to positions and don't have time to delve into as deeply as appears would have to do so to resolve.
I don't know otomh that there is a clean solution to produce the effect you're looking for; probably is, but I'm not GUI kind of guy, so my knowledge of the ins and outs of gui layout is very limited.
Possibly a way to work around the issue would be something like
hUIF=uifigure;
hTA=uitextarea(hUIF,'Position',[200 200 51 100],"Value",["";"";"";"Hello";""]);
where you size the text area to fit a given number (odd) of lines and then space down to show text where it is wanted. This, of course, is extremely fragile and also defeats the purpose of the control.
Again, if you would describe what the GUI is intended to be doing functionally instead of just focusing on a preconceived notion, somebody could probably help redesign the UI to provide that functionality cleanly without all these machinations trying to make something of what isn't.

请先登录,再进行评论。


dpb
dpb 2023-6-15
编辑:dpb 2023-6-15
Well, it CAN be done; don't know that I would recommend it still, but...
hUIF=uifigure;
pLbl=[200 200 50 100]; % label position vector (L, R, W, H) in pixels relative figure
hLbl=uilabel(hUIF,'Position',pLbl,"Text","Hello",'VerticalAlignment','center','BackgroundColor','w');
pAx=pLbl+[0 0 1 1]; % axis position one pixel wider/taller than label...
hAx=axes(hUIF,'Position',pAx,'color','none','Units','pixels'); % actual position is way out in right field somewhere???
hAx.Position=pAx; % Mandatory to place axes in visible location. WHY IS UNKNOWN????
hAx.Box='on'; % draw the outer outlines
yticks(hAx,[]) % don't show ticks/labels
xticks(hAx,[]
creates a label with a box apparently drawn around it.
The "tricks" are:
  1. The initial positioning of the axes is somewhere off in never-never land even though it's directed to be at the same offset from the figure as that of the label. Rewriting/repositioning after it is created seems to fix this. No idea what this is all about...
  2. The axes has to be at least one pixel taller/wider than the label for the top and RH axes lines to be visible. Hence the adjustment of the label coordinates vector when creating the axes. This is the issue couldn't figure out before; dawned on me overnight what the likely issue was/is...

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by