Fonts and Colors for Cross-Platform Compatibility

Default System Font

By default, user interface controls (uicontrols) use the default font for the platform on which they are running. For example, when displaying your GUI on PCs, user interface controls use MS San Serif. When your GUI runs on a different platform, they use that computer's default font. This provides a consistent look with respect to your GUI and other application GUIs on the same platform.

If you have set the FontName property to a named font and want to return to the default value, you can set the property to the string, 'default'. This ensures that MATLAB® software uses the system default at run-time.

pbh1.FontName = 'default';

Specify a Fixed-Width Font

If you want to use a fixed-width font for a user interface control, set its FontName property to the string, 'fixedwidth'. This special identifier ensures that your GUI uses the standard fixed-width font for the target platform.

You can find the name of the fixed-width font that is used on a given platform by querying the root FixedWidthFontName property.


Use a Specific Font Name

You can specify an actual font name (such as Times or Courier) for the FontName property. However, doing so may cause your GUI to appear differently than you intended when run on a different computer. If the target computer does not have the specified font, it substitutes another font that may not look good in your GUI or may not be the standard font used for GUIs on that system. Also, different versions of the same named font may have different size requirements for a given set of characters.

Standard Background Color

MATLAB software uses the standard system background color of the system on which the GUI is running as the default component background color. This color varies on different computer systems, e.g., the standard shade of gray on the PC differs from that on UNIX® system, and may not match the default GUI background color.

You can make the GUI background color match the default component background color. This code gets the default component background color and assign it to the figure.

defaultBackground = get(groot,'defaultUicontrolBackgroundColor');
fh.Color = defaultBackground;
Was this topic helpful?