center text in app designer
12 views (last 30 days)
Show older comments
hi, it' possibile to center vertically "HALLO" in field?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1410004/image.png)
2 Comments
dpb
on 13 Jun 2023
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... :)
Answers (2)
Voss
on 13 Jun 2023
Moved: Matt J
on 14 Jun 2023
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 Comments
dpb
on 15 Jun 2023
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
on 15 Jun 2023
Edited: dpb
on 15 Jun 2023
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...
0 Comments
See Also
Categories
Find more on Graphics Object Properties 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!