Creating Graphical User Interfaces |
Designing for Cross-Platform Compatibility
You can use specific property settings to create a GUI that behaves more consistently when run on different platforms:
FontName
property).
BackgroundColor
property).
Units
property).
By default, uicontrols use the default font for the platform on which they are running. For example, when displaying your GUI on PCs, uicontrols uses MS San Serif. When your GUI runs on a different platform, it uses that computer's default font. This provides a consistent look with respect to your GUI and other application GUIs.
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 uses the system default at runtime.
From within the GUI M-file, use the set command. For example, if there is a push button in your GUI and its handle is stored in the pushbutton1
field of the handles
structure, then the statement,
sets the FontName
property to use the system default. You can also use the Property Inspector to set this property:
Specifying a Fixed-Width Font
If you want to use a fixed-width font for a uicontrol, 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.
Using 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 look poorly when run on a different computer. If the target computer does not have the specified font, it will substitute 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.
Using Standard Background Color
By default, uicontrols use the standard background color for the platform on which it is running (e.g., the standard shade of gray on the PC differs from that on UNIX). When your GUI is deployed on a different platform, it uses that computer's standard color. This provides a consistent look with respect to your GUI and other application GUIs.
If you change the BackgroundColor
to another value, MATLAB always uses the specified color.
Cross-Platform Compatible Figure 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.
For this reason, GUIDE sets the figure Units
property to characters
.
System-Dependent Units
Figure character units are defined by characters from the default system font; one character unit equals the width of the letter x in the system font. The height of one character is the distance between the baselines of two lines of text (note that character units are not square).
GUIDE sets the figure Units property to characters
so your GUIs automatically adjust the size and relative spacing of components as the GUI displays on different computers. For example, if the size of the text label on a component becomes larger because of different system font metrics, then the component size and the relative spacing between components increases proportionally.
Application Data | Types of Callbacks |