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

조회 수: 24 (최근 30일)
SRUSHTI KHATAU
SRUSHTI KHATAU 2022년 2월 2일
편집: Nivedita 2023년 11월 14일
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
Rik
Rik 2022년 2월 2일
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 2022년 2월 2일
Okay. Thank you for replying. I will try this option. But, the problem is I have to use large number of Text Area.

댓글을 달려면 로그인하십시오.

답변 (1개)

Nivedita
Nivedita 2023년 11월 14일
편집: Nivedita 2023년 11월 14일
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