How to create a textarea component in MATLAB
Matlab offers tools for developing GUI applications. It provides functions that can create TextFields, Labels, Buttons, and many more, along with properties to manipulate the components. In this article, we will learn to create a TextArea Component using Matlab.
Creating a textarea component
A Text Area component is a UI component that allows us to input multiple lines of text. To create a text area object, we use the Matlab function uitextarea(), which accepts two optional parameters, the parent window in which this component resides and its values.
The parent is a figure or window that will hold all the components of our GUI. The Name-Value pair is the value that the text area will be initialized with.
Properties of textarea component
Properties of UI components are used to access and mutate their content as well as their appearances. Use dot notation to refer to a specific property.
A few of the important properties of the text area component are as follows:
- Value: We can use the Value property of a text area to access or set its content.
- Placeholder: The text that will be shown in the text area when it’s empty. Default is an empty string.
- Horizontal Alignment: Specifies the alignment of the text within the text area. possible options are left, right or centre. Default is ‘left’.
- WordWrap: Wraps the content to match the container’s width. Default is ‘on’.
- FontName: Used to set the font name for the content of the text area.
- FontSize: Used to set the font size of the text.
- FontWeight: this property is used to set the boldness level of the text in the text area.
- FontAngle: Use to change the angle of the font.
- FontColor: Used to change the font colour.
- BackgroundColor: This property helps to set the background colour of the text.
- Enable: Using this property a text area can be disabled or enabled for use.
- Position: accepts a list of 4 values, the first 2 are locations and the last two are the size of the text area.
- Visible: Visibility of the text area is controlled by this property. Default is ‘on’.
There are three syntaxes of uitextarea:
- textareaObject = uitextarea;
- textareaObject = uitextarea(parent);
- textareaObject = uitextarea(parent, Name, Value);
Now we see the first syntax without any parameters. It creates the text area component and the Matlab creates a figure window to hold the component.
uitextarea also accepts an optional parent container or window. If you have defined a window and want to add a text area to it, then textareaObject = uitextarea(parent) used.
We also have the option to set the properties while instantiating a text area.
Using uifigure, we created a figure window which will be our parent window. It will hold other components. The uitextarea() is used to create a text area component, and we pass the parent window as its parameter and a key-value pair to set its property Value, which determines the text area’s content. The Position property accepts a 4 value list, the first 2 values are the component’s position in the parent window, and the last two are the size of the components (width and height).
Output before scroll:
Now, we can use the scroll function with the component and the location where to scroll like ‘bottom’. as parameter.
Output after scroll: