center text in app designer
이전 댓글 표시
hi, it' possibile to center vertically "HALLO" in field?

댓글 수: 2
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
2023년 6월 13일
답변 (2개)
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
2023년 6월 14일
That's still a textarea object; you'll have to change to a UI label control for it to have a vertical alignment property -- but if there is a list to put into the control it makes no sense to use a label for the purpose.
Looks like a case of "trying to put a square peg into a round hole" kind of issue to me...
Explain what your end object is for this control (and not just how you're trying to format it; what the actual function it is to accomplish in the app for the user).
piero
2023년 6월 14일
It's still referring to a textarea object, not a label control.
If you replaced the actual text area object with a label, then the code for the text area callback isn't ever going to be called; and if it were the VerticalAlignment property would raise an error.
hUIF=uifigure;
hLbl=uilabel('Position',[200 200 51 100],"Text","Hello",'VerticalAlignment','center','BackgroundColor','w');
Oh, can't do that here...so here's an image done locally

As you can see, if you use a uilabel object, then the vertical alignment property works just fine; but you have to use a control type that supports the feature.
piero
2023년 6월 14일
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.
piero
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:
- 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...
- 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...
카테고리
도움말 센터 및 File Exchange에서 Language Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



