How to give vertical alignment to Text Area component of App designer?

19 visualizaciones (últimos 30 días)
SRUSHTI KHATAU
SRUSHTI KHATAU el 2 de Feb. de 2022
Editada: Nivedita el 14 de Nov. de 2023
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 comentarios
Rik
Rik el 2 de Feb. de 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.
SRUSHTI KHATAU
SRUSHTI KHATAU el 2 de Feb. de 2022
Okay. Thank you for replying. I will try this option. But, the problem is I have to use large number of Text Area.

Iniciar sesión para comentar.

Respuestas (1)

Nivedita
Nivedita el 14 de Nov. de 2023
Editada: Nivedita el 14 de Nov. de 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.

Community Treasure Hunt

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

Start Hunting!

Translated by