center text in app designer

hi, it' possibile to center vertically "HALLO" in field?

2 Comments

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... :)
:P
i want alignement verticaly not horizontaly

Sign in to comment.

Answers (2)

Voss
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

piero
piero on 14 Jun 2023
Edited: piero on 14 Jun 2023
thanks for support but i can't find "Text"
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).
I tried your suggestion but the problem remains
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;
Error using matlab.internal.lang.capability.Capability.require
This functionality is not available on remote platforms.

Error in matlab.ui.internal.uifigureImpl (line 32)
Capability.require(Capability.WebWindow);

Error in uifigure (line 26)
window = matlab.ui.internal.uifigureImpl(varargin{:});
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.
thanks for your help..i managed to align it as i wanted.The only problem is that the type "label" is not a "text" and it has no border..do you know how to draw it?
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.
thanks

Sign in to comment.

dpb
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:
  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...

Categories

Asked:

on 13 Jun 2023

Edited:

dpb
on 15 Jun 2023

Community Treasure Hunt

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

Start Hunting!