How to give vertical alignment to Text Area component of App designer?
25 views (last 30 days)
Show older comments
Hi,
I want to add text box in my UI. But I want that Text alignment to be vertically and horizontally in center. Currently, it only has horizontal alignment option
Please tell me some solution for this.
4 Comments
Rik
on 2 Feb 2022
For normal figures this is already a problem. The common solution is to use a text object centered in an axes object. For non-editable fields something like that should be possible in AppDesigner/uifigures as well. For editable text fields I can't think of anything practical.
Answers (1)
Nivedita
on 14 Nov 2023
Edited: Nivedita
on 14 Nov 2023
Hello Srushti,
I understand that you want the text alignment inside the text area to be vertically and horizontally in center.
You can create a workaround by adjusting the "Position" property of the text box and manipulating the "Text" property to create the appearance of vertical center alignment. Here's a simple example:
function startupFcn(app)
%Create a TextArea
app.TextArea = uitextarea(app.UIFigure);
app.TextArea.Position = [100 100 200 200];
app.TextArea.HorizontalAlignment = 'center';
%Create a string with newline characters to simulate vertical centering
app.TextArea.Value = {''; '';'';'';'';'Your Text'; ''};
end
In this example, the "Value" property of the TextArea is set to a cell array of strings. The first few and last strings are empty, effectively pushing the text string ('Your Text') towards the center of the TextArea. You may need to adjust the number of empty strings based on the height of your TextArea and the size of your text.
For more information on the properties of "TextArea", you can refer to the followiung documentation link:
I hope this helped!
Regards,
Nivedita.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!