How to Create a Textarea Component in MATLAB?


In MATLAB, we have a built-in GUI App Designer environment that allows us to develop various types of GUI (Graphical User Interface) applications with proper knowledge of software engineering and programming.

In this MATLAB’s app designer environment, we can create various kinds of GUI components such as TextFields, Buttons, NumEditFields, Labels, Hypertext, and more.

In this tutorial, we will explore how to create a TextArea Component in MATLAB app.

TextArea Component in MATLAB

In MATLAB, the TextArea is a GUI component allows application users to input a string of text. MATLAB provides a built-in function ‘uitextarea’ to create a TextArea component in the MATLAB application.

This function can have the following three syntaxes depending different use cases −

  • TextAreaObject = uitextarea;

  • TextAreaObject = uitextarea(parent);

  • TextAreaObject = uitextarea(parent, Name, Value);

TextArea Component Properties in MATLAB

The TextArea component has the following properties that we can apply to text area object in our MATLAB app −

  • Value − This is a text property of the text area component. It allows us to set the content of the text area field.

  • Character Limits − This property allows us to define the minimum and maximum character limit of the text area component.

  • Input Type − This property allows us to set a valid input text content, it can be a text, letter, digit, and alphanumeric.

  • Placeholder − This property allows us to show a message when the text area is empty.

  • Horizontal Alignment − This property of text area component allows us to set the alignment of the text in the text field. Its default value is left alignment.

  • Font Name − Allows to set the font of the text area component.

  • Font Size − Allows to set a font size of the text.

  • Font Wright − Allows to make the text bold or unbold.

  • Font Angle − Allows to make the text italic or non-italic.

  • Font Color − Allows to change the color of the text.

  • Background Color − Allows to change the background color of the text.

  • Interactivity − This property of the text area component allows to set the text field object parameters such as ‘Visible’, ‘Editable’, ‘Enable’, ‘Tooltip’, and ‘Context Menu’.

  • Position − This property allows us to change the location and size of the text area. It takes four input values, where the first two represents location of the text area and the last two represents the size of the text area.

Let us now create different types of TextArea components using different syntaxes of the ‘uitextarea’ function.

(1). Text Area Component with Default Properties

Syntax

In MATLAB, to create a textarea component with default properties, we can use the following syntax of the ‘uitextarea’ function −

textarea_comp = uitextarea;

Matlab Example (1)

The following MATLAB program demonstrate the implementation of this syntax.

% MATLAB program to create a text area component with default properties
% Create a text area component with default properties
textarea_comp = uitextarea;

Output

Explanation

This MATLAB code will generate a figure window with default properties containing a text area component.

(2). Text Area Component With Parent Container

Syntax

The following syntax of the ‘uitextarea’ function can be used to create a text area component with its parent container that will hold the text area.

textarea_comp = uitextarea(parent);

Matlab Example (2)

The following MATLAB program demonstrates the implementation of this syntax.

% MATLAB program to create a text area component with its parent container
% Create a figure as a parent container to hold the text area
fig = uifigure('Name', 'Text Area Container');

% Create a text area component with parent container
textarea_comp = uitextarea(fig);

Output

Explanation

This MATLAB code creates a figure window with title ‘Text Area Container’ that hold the text area field.

(3). Text Area Component with Specific Properties

Syntax

The following syntax of the ‘uitextarea’ function can be used to create a text area component with specific properties such as parent container, font color, placeholder, etc.

textarea_comp = uitextarea(parent, 'Name', 'Value',…);

The following MATLAB program demonstrates the implementation of this syntax to create a text area component with specified properties.

Matlab Example (3)

% MATLAB code to create text area with custom properties
% Create a figure window to hold the text area
fig = uifigure('Name', 'Text Area with Custom Properties');

% Create a text area with specified properties
textarea_comp = uitextarea(fig, 'Placeholder', 'Enter your text here...', 'Position', [50, 50, 200, 100], 'FontColor', 'green');

Output

Explanation

This MATLAB code will create a figure window with title ‘Text Area with Custom Properties’. It holds the text area component with specified placeholder, position, and font color.

Conclusion

This is all about creating a text area component in MATLAB application. The text area component is a GUI component that allows user to input text content. We have demonstrated different methods to create a text area component with default and specified properties with the help of MATLAB programs.

Updated on: 06-Sep-2023

50 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements