MATLAB Answers

How can I change the default units in GUIDE

39 views (last 30 days)
Yuval Cohen
Yuval Cohen on 10 Apr 2014
Commented: Image Analyst on 17 Apr 2014
Hello, I use GUIDE for many of my GUIs. I like using 'pixels' for the figure and all uicontrols. Unfortunately, the default units are 'characters' and I have to manually change the unit value for every new uicontrol I add.
Is there a way to change the default units?
Thank you, Yuval

  0 Comments

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 17 Apr 2014
You can't change the default as far as I know. You need to set up each one. However they don't need to be done one at a time in the Property Inspector, and you don't need to write something into every CreateFcn. You can set them all as a group (well almost all). What you can do is to drag a box around all the controls on your figure to select all of them. Then double-click on any one of them to bring up the Property Inspector. It will list only those properties that apply to all of them, and some will be missing because some controls don't have certain properties. Fortunately "Units" is one of those that will be shown. You can change the units to pixels for all the controls that you have selected, then close the property inspector. The only ones it won't apply to are those controls that are located inside a panel (group box). For those you have to set them one at a time.

  0 Comments

Sign in to comment.


nl2605
nl2605 on 17 Apr 2014
In the CreateFcn you can change the units as you want them to be. But yes, you will have to write it in every CreateFcn of your figure components.

  0 Comments

Sign in to comment.


Sean de Wolski
Sean de Wolski on 17 Apr 2014
In general, you can do this if you were making programmatic UIs. However, GUIDE sets its own defaults that can't be changed to my knowledge.
With a regular figure:
hFig = figure;
set(hFig,'Defaultuicontrolunits','pixels')
set(hFig,'Defaultaxesunits','pixels')
set(hFig,'Defaultuipanelunits','pixels')
I would recommend IA's approach. You can also right click a graphics component in GUIDE to make a copy of it. That way you change the properties once, right click and drag to get an identical object.

  1 Comment

Image Analyst
Image Analyst on 17 Apr 2014
Neat trick (right click and drag). I was always using control c, control v to create a copy of a control.

Sign in to comment.

Sign in to answer this question.

Products