uihyperlink
Description
creates a hyperlink
component in a new figure window and returns the hlink
= uihyperlinkHyperlink
object.
MATLAB® calls the uifigure
function to create the
figure.
specifies hyperlink properties using one or more name-value arguments. For example, you can
specify the display text and URL of the hyperlink using the hlink
= uihyperlink(___,Name,Value
)Text
and
URL
name-value arguments. Use this option with any of the input
argument combinations in the previous syntaxes.
Examples
Create Hyperlink Component
Create a hyperlink component. Change the display text to
'MathWorks'
and set it to link to the MathWorks® home page.
fig = uifigure; hlink = uihyperlink(fig); hlink.Text = "MathWorks"; hlink.URL = "https://www.mathworks.com/";
When the app user clicks on the link, the MathWorks home page opens in a new browser tab.
Create Tooltip to Display URL
Create a default hyperlink component.
fig = uifigure; hlink = uihyperlink(fig);
Change the URL to link to the MathWorks home page. Add a tooltip that shows the URL when the app user hovers their pointer over the hyperlink.
hlink.URL = "https://www.mathworks.com";
hlink.Tooltip = hlink.URL;
Resize Hyperlink
Create a default hyperlink.
fig = uifigure; hlink = uihyperlink(fig);
Change the link text and URL.
hlink.Text = "MathWorks home page"; hlink.URL = "https://www.mathworks.com/"
The link text is clipped because the current size is too small for the new text.
Determine the current link size by getting the third and fourth elements of the
Position
property value.
size = hlink.Position(3:4)
size = 70 22
Change the size to accommodate the new text.
hlink.Position(3:4) = [150 22];
Open File on Click
To make a link open a file on the app user's system when clicked, use
the file:///
URL scheme.
Create a hyperlink component. Open an HTML file named myfile.html
when an app user clicks the hyperlink by setting the URL
property.
Specify the URL by using the file:///
URL scheme followed by the file
location and name.
fig = uifigure; hlink = uihyperlink(fig); file = fullfile(pwd,"myfile.html") hlink.URL = "file:///" + file;
Send Email on Click
To make a link send an email when clicked, use the
mailto:
URL scheme.
Create a default hyperlink component.
fig = uifigure; hlink = uihyperlink(fig);
To run this example, replace the value for email
with a valid
email address. When the app user clicks on the link, the default mail client opens a new
email with the destination field pre-populated with email
.
email = 'myaddress@provider.ext'; hlink.URL = ['mailto:' email];
Code Response to Click
Create a hyperlink with a custom effect: it creates a plot as well as
opening a URL when the app user clicks it. To do this, create a set of UI axes and a
HyperlinkClickedFcn
callback that creates a plot in these
axes.
Create a file named hyperlinkPlot.m
on your MATLAB path that contains the following code. This code creates a window
containing a hyperlink and a set of UI axes. When the app user clicks the link, first
the app user's browser loads the MATLAB product page, then the HyperlinkClickedFcn
callback
plots some data.
function hyperlinkPlot % Create a figure window and UI axes fig = uifigure; ax = uiaxes(fig); % Create a hyperlink hlink = uihyperlink(fig,... "Position",[200 350 70 22], ... "Text","MATLAB", ... "URL","https://www.mathworks.com/products/matlab.html", ... "HyperlinkClickedFcn",@(hlink,event) plotHyperlinkClicked(hlink,ax)); end % Create the function for the HyperlinkClickedFcn callback function plotHyperlinkClicked(hlink,ax) L = 160*membrane(1,100); s = surf(ax,L); s.EdgeColor = 'none'; end
Run hyperlinkPlot
, then click the link. MATLAB opens the URL, then plots the data.
Input Arguments
parent
— Parent container
Figure
object (default) | Tab
object | Panel
object | ButtonGroup
object | GridLayout
object
Parent container, specified as a Figure
object created using the uifigure
function or one of its child
containers: Tab
, Panel
, ButtonGroup
, or GridLayout
. If you do not specify a parent container, MATLAB calls the uifigure
function to create a new Figure
object that serves as the parent container.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: uihyperlink('Text','Click me')
specifies the hyperlink
displays the text Click me
.
Note
The properties listed here are a subset of the available properties. For the full
list, see Hyperlink
.
Text
— Hyperlink display text
'Hyperlink'
(default) | character vector | cell array of character vectors | string scalar | string array | 1-D categorical array
Hyperlink display text, specified as a character vector, cell array of character vectors, string scalar, string array, or 1-D categorical array. Use a cell array of character vectors or a string array to specify multiple lines of text.
Example: 'Click here'
Example: {'Click' 'Here'}
URL
— Hyperlink URL
''
(default) | character vector | string scalar
Hyperlink URL, specified as a character vector or string scalar. When the hyperlink is clicked, the web address opens in a new browser tab. If the user is running the app in a browser via MATLAB Online™ or as a web app, the new tab opens in the current browser. Otherwise, the new tab opens in the default browser on the user's system.
HyperlinkClickedFcn
— Hyperlink clicked callback
''
(default) | function handle | cell array | character vector
Hyperlink clicked callback, specified as one of these values:
A function handle.
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
This callback executes after the URL opens when the user clicks the hyperlink.
This callback function can access specific information about the user's interaction with the hyperlink. MATLAB passes this information in a HyperlinkClickedData
object as the second argument to your callback function. In App Designer, the argument is called event
. You can query the object properties using dot notation. For example, event.Source
returns the Hyperlink
object. The HyperlinkClickedData
is not available to callback functions specified as character vectors.
The following table lists the properties of the HyperlinkClickedData
object.
Property | Value |
---|---|
EventName | 'HyperlinkClicked' |
Source | Component that executes the callback |
For more information about writing callbacks, see Callbacks in App Designer.
Position
— Hyperlink location and size
[100 100 70 22]
(default) | [left bottom width height]
Hyperlink location and size, relative to the parent, specified as the vector [left bottom width height]
. This table describes each element in the vector.
Element | Description |
---|---|
left | Distance from the inner left edge of the parent container to the outer left edge of the label |
bottom | Distance from the inner bottom edge of the parent container to the outer bottom edge of the label |
width | Distance between the right and left outer edges of the label |
height | Distance between the top and bottom outer edges of the label |
The Position
values are relative to the drawable area of the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.
All measurements are in pixel units.
Example: [100 100 100 20]
Version History
Introduced in R2021a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)