Documentation Center

  • Trial Software
  • Product Updates

Design Programmatic GUIs 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.

You can use the set command to set this property. For example, if there is a push button with handle pbh1 in your GUI, then the statement


sets the FontName property to use the system 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. The following statements retrieve the default component background color and assign it to the figure.

defaultBackground = get(0,'defaultUicontrolBackgroundColor');

The figure Color property specifies the figure's background color.

The following figures illustrate the results with and without system color matching.

Cross-Platform Compatible Units

Cross-platform compatible GUIs should look correct on computers having different screen sizes and resolutions. Since the size of a pixel can vary on different computer displays, using the default figure Units of pixels does not produce a GUI that looks the same on all platforms. Setting the figure and components Units properties appropriately can help to determine how well the GUI transports to different platforms.

Units and Resize Behavior

The choice of units is also tied to the GUI's resize behavior. The figure Resize and ResizeFcn properties control the resize behavior of your GUI.

Resize determines if you can resize the figure window with the mouse. The on setting means you can resize the window, off means you cannot. When you set Resize to off, the figure window does not display any resizing controls to indicate that it cannot be resized.

ResizeFcn enables you to customize the GUI's resize behavior and is valid only if you set Resize to on. ResizeFcn is the handle of a user-written callback that is executed when a user resizes the GUI. It controls the resizing of all components in the GUI. See documentation for the figure ResizeFcn property for an example of resizing.

The following table shows appropriate Units settings based on the resize behavior of your GUI. These settings enable your GUI to automatically adjust the size and relative spacing of components as the GUI displays on different computers and when the GUI is resized.


Default Units

Resize = on
ResizeFcn = []

Resize = off





User interface controls (uicontrol) such as push buttons, sliders, and edit text components












Button group




    Note   The default settings shown in the table above are not the same as the GUIDE default settings. GUIDE default settings depend on the GUIDE Resize behavior option and are the same as those shown in the last two columns of the table.

About Some Units Settings

Characters.  Character units are defined by characters from the default system font. The width of a character unit equals the width of the letter x in the system font. The height of a character unit is the distance between the baselines of two lines of text. Note that character units are not square.

Normalized.  Normalized units represent a percentage of the size of the parent. The value of normalized units lies between 0 and 1. For example, if a panel contains a push button and the button units setting is normalized, then the push button Position setting [.2 .2 .6 .25] means that the left side of the push button is 20 percent of the panel width from the left side of the panel; the bottom of the button is 20 percent of the panel height from the bottom of the panel; the button itself is 60 percent of the width of the panel and 25 percent of its height.

Familiar Units of Measure.  At times, it may be convenient to use a more familiar unit of measure, e.g., inches or centimeters, when you are laying out the GUI. However, to preserve the look of your GUI on different computers, remember to change the figure Units property back to characters, and the components' Units properties to characters (nonresizable GUIs) or normalized (resizable GUIs) before you save the code file.

Was this topic helpful?