- Undocumented Matlab - https://undocumentedmatlab.com -
Undocumented button highlighting
Posted By Yair Altman On February 5, 2014 | 1 Comment
One of my consulting clients approached me yesterday with a mystery: In his GUIDE-generated GUI, one of the buttons had a bluish tint, and no obvious property seemed to control this or to differentiate it from its sibling controls. Here’s a parred-down version of his GUI:
Our first attempts to understand the situation were to modify the button control’s obvious suspect properties:
So maybe GUIDE attached some funky property value to the control? Let’s investigate. Remembering that the GUIDE-generated *.fig file is simply a standard MAT file [6] with a different extension, we can load it into the Matlab workspace and dissect it. Drilling down the GUI hierarchy we find:
>> data = load('myGUI.fig', '-mat')
data =
hgS_070000: [1x1 struct]
>> d.hgS_070000.children(9).properties
ans =
Units: 'pixels'
Callback: [function_handle]
Position: [20 20 60 20]
String: 'Yes'
Value: 1
ApplicationData: [1x1 struct]
>> d.hgS_070000.children(10).properties
ans =
Units: 'pixels'
Callback: [function_handle]
Position: [100 20 60 20]
String: 'No'
ApplicationData: [1x1 struct]
When we compare the information that GUIDE stored for the two buttons we see that it stored an extra Value property for the ‘Yes’ button, and used the default HG value [7] for the ‘No’ button. Let’s compare the property values in run-time (I’m using my objDiff utility [8] for this):
>> hButton1 = findall(gcf, 'String', 'Yes');
>> hButton2 = findall(gcf, 'String', 'No');
>> props1 = get(hButton1);
>> props2 = get(hButton2);
>> objdiff(props1, props2)
ans =
Extent: {[0 0 24 19] [0 0 17 19]}
Position: {[20 20 60 20] [100 20 60 20]}
String: {'Yes' 'No'}
Value: {[1] [0]}
This pretty much nails it: pushbutton highlighting is controlled via the Value property. According to the official documentation [9], the Value property has no meaning for push-buttons, only for other uicontrol styles. This is obviously not so:
set(hButton, 'Value', 1); % Turn button highlighting on
set(hButton, 'Value', 0); % Turn button highlighting off (can use any value ~=1)
Under the hood, updating the Value property sets the pushbutton’s underlying Java control [10]‘s Selected property to true. Note that the Java Selected property is entirely unrelated to Matlab’s Selected property (which has no underlying Java counterpart). I do not understand the design decision that let to this, but since it has been like this for many years I see little chance that it will be changed in the near future.
In any case, the Java Selected property indeed has a visual effect, but the actual effect depends on the current operating system and Look-&-Feel (LnF). You can play around with the LnF [11] to achieve various other alternative highlighting effects, or customize one of your own.
If this topic has piqued your interest, consider joining my Advanced Matlab GUI course [12] in London on 12-14 March, 2014. In this course/seminar I will explore numerous other ways by which we can customize Matlab’s GUI and graphics in ways that you never knew were even possible! This is a unique opportunity to take your Matlab skills to a higher level within just a few days. This training is not offered anywhere else.
Categories: GUI, Low risk of breaking in future versions, UI controls, Undocumented feature
Article printed from Undocumented Matlab: https://undocumentedmatlab.com
URL to article: https://undocumentedmatlab.com/articles/undocumented-button-highlighting
URLs in this post:
[1] HTML label: http://undocumentedmatlab.com/blog/button-customization/
[2] HTML image: http://undocumentedmatlab.com/blog/images-in-matlab-uicontrols-and-labels/
[3] HTML labels for uicontrols: http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/
[4] control’s border: http://undocumentedmatlab.com/blog/customizing-uicontrol-border/
[5] fly-over appearance feature: http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/
[6] *.fig file is simply a standard MAT file: http://undocumentedmatlab.com/blog/fig-files-format/
[7] default HG value: http://undocumentedmatlab.com/blog/getting-default-hg-property-values/
[8] objDiff utility: http://www.mathworks.com/matlabcentral/fileexchange/14395-objdiff-generic-object-comparator
[9] official documentation: http://www.mathworks.com/help/matlab/ref/uicontrol_props.html#bqxoir7
[10] underlying Java control: http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/
[11] play around with the LnF: http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/
[12] Advanced Matlab GUI course: http://undocumentedmatlab.com/training/advanced-matlab-seminars-london-10-14-march-2014/
[13] Borderless button used for plot properties : https://undocumentedmatlab.com/articles/borderless-button-used-for-plot-properties
[14] Toolbar button labels : https://undocumentedmatlab.com/articles/toolbar-button-labels
[15] Button customization : https://undocumentedmatlab.com/articles/button-customization
[16] HG's undocumented parameters interface : https://undocumentedmatlab.com/articles/hgs-undocumented-parameters-interface
[17] getundoc – get undocumented object properties : https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties
[18] Undocumented classdef attributes : https://undocumentedmatlab.com/articles/undocumented-classdef-attributes
Click here to print.
Copyright © Yair Altman - Undocumented Matlab. All rights reserved.
1 Comment To "Undocumented button highlighting"
#1 Comment By Adee Ran On June 3, 2021 @ 13:51
Yair, once again, I find the answer to the issue that annoy me is in your site since long ago.
Both the highlighting control and focus control (using uicontrol() ) are simple, important, but undocumented.
Thank you.