Main Content

uisetfont

Open font selection dialog box

Description

uisetfont opens a modal Font dialog box with default font name and font style values selected. If the user clicks OK, then the selected font properties are returned to the MATLAB® Command Window. If the user clicks Cancel, or the close button (X) in the dialog box title bar, then a value of 0 is returned to the Command Window.

uisetfont(h) specifies the object on which the Font dialog box will operate. The values displaying in the dialog box when it opens are the current settings for that object.

The value of h can be a text, axes, or uicontrol object.

example

uisetfont(optsin) initializes the Font dialog box selections with the values defined for the specified optsin structure.

uisetfont(___,title) specifies a custom title for the Font dialog box. This syntax can include any of the input arguments in the previous syntaxes.

optsout = uisetfont(___) returns the values selected in the dialog box to the optsout structure when the user clicks OK. If the user clicks Cancel or an error occurs, then optsout is set to 0. This syntax can specify no input arguments or any of the input arguments in the previous syntaxes.

example

Examples

collapse all

Create a plot containing a text annotation.

f = figure('Position',[200 200 392 294]);
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y);
t = text(pi,0,'\leftarrow sin(\pi)');

Plot of a sine function with the text "sin(π)" pointing to the curve

Open the Font dialog box, and select the Bold Italic style. (The font names displayed in the dialog box are system-dependent.)

optsout = uisetfont(t);

Font dialog box. The dialog box contains fields to select the font name, style, and size, and displays sample text with the selected font characteristics. The bottom of the dialog box has two buttons: "OK" and "Cancel".

Click OK. The font style changes in the plot annotation.

Plot of a sine function with the text "sin(π)" pointing to the curve. The text is bold and italic.

Input Arguments

collapse all

Target object for font changes, specified as an Axes, Text, or UIControl object.

Font values, specified as a structure of font properties.

The following table lists the structure fields, the default values, and the dialog box controls with which a user can change the values.

Structure Fields

Structure FieldDefault ValueDialog Box Control
FontNamesystem-dependentFont list.
FontWeight'normal'Style list.
FontAngle'normal'Style list.
FontUnits'points' Not provided because the value of FontUnits is always 'points' for the supported objects.
FontSizesystem-dependentSize list

A structure field value of 'normal' corresponds to Plain in the dialog box Style list.

The user can select a Size value from the list or type in an unlisted value. If the user types a floating-point number, MATLAB rounds it to the closest integer value before storing it.

Example: optsin.FontWeight = 'bold';

Dialog box title, specified as a character vector or a string scalar.

Example: 'Font Selection'

Output Arguments

collapse all

Font values, returned as a structure of font property values. The structure fields are:

  • FontName

  • FontWeight

  • FontAngle

  • FontUnits

  • FontSize

If the user typed a floating-point number for the dialog box field that corresponds to the FontSize value, then MATLAB rounds it to the closest integer value before returning it.

More About

collapse all

Modal Dialog Box

A modal dialog box prevents a user from interacting with other MATLAB windows before responding to the dialog box.

Version History

Introduced before R2006a

See Also

| |