**- Undocumented Matlab - https://undocumentedmatlab.com -**

Customizing Matlab labels

Posted By Yair Altman On November 11, 2009 | __12 Comments__

As I was deliberating the topic of my weekly article, a new CSSM newsreader thread arrived today to immediately conclude the debate: The CSSM poster asked ^{[1]} how Matlab labels can be modified to display non-ASCII characters such as the ∀ or β math symbols.

As you may recall, unlike axes text labels that support Tex/Latex, and unlike other ** uicontrol**s like buttons or listboxes that support HTML

In the above-mentioned thread, Matt Whitaker, a longstanding CSSM contributor and a Matlab-Java veteran gave a solution that shows how seemingly difficult questions sometimes have simple solutions right beneath our noses. His solution was to simply replace the

```
%show the 'for all' and 'beta' symbols
labelStr = '∀β
```**bold** *label';
jLabel = javaObjectEDT('javax.swing.JLabel',labelStr);
[hcomponent,hcontainer] = javacomponent(jLabel,[100,100,40,20],gcf);
*

Note that the standard Matlab text

Categories: GUI, Handle graphics, Hidden property, Java, Low risk of breaking in future versions, UI controls

12 Comments (Open | Close)

Article printed from Undocumented Matlab: **https://undocumentedmatlab.com**

URL to article: **https://undocumentedmatlab.com/articles/customizing-matlab-labels**

URLs in this post:

[1] asked: **https://www.mathworks.com/matlabcentral/newsreader/view_thread/265569**

[2] support HTML: **http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/**

[3] JLabel: **http://java.sun.com/javase/6/docs/api/javax/swing/JLabel.html**

[4] FindJObj utility: **http://www.mathworks.com/matlabcentral/fileexchange/14317**

[5] javax.swing.JComponent: **http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html**

[6] Transparent labels : **https://undocumentedmatlab.com/articles/transparent-labels**

[7] Customizing axes part 5 – origin crossover and labels : **https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels**

[8] Customizing axes tick labels : **https://undocumentedmatlab.com/articles/customizing-axes-tick-labels**

[9] Images in Matlab uicontrols & labels : **https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels**

[10] Customizing Matlab uipanels : **https://undocumentedmatlab.com/articles/customizing-matlab-uipanels**

[11] Hyperlink text labels : **https://undocumentedmatlab.com/articles/hyperlink-text-labels**

[12] : **http://www.mathworks.com/discovery/matlab-gui.html**

[13] : **http://www.mathworks.com/help/releases/R2015b/pdf_doc/matlab/buildgui.pdf**

Click here to print.

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.

12 Comments To "Customizing Matlab labels"

#1 CommentByNickOn May 28, 2010 @ 19:00I don’t know if this is obvious as I don’t know Java, but you can change the gray background of the JLabel by defining a java.awt.Color object and using setBackground:

mycolor = javaObjectEDT(‘java.awt.Color’, rgb_code)

setBackground(jLabel, mycolor);

The rgb_code is an integer that seems to be correspond to RGB as follows:

256^2*(0-255 red level) + 256*(0-255 green level) + (0-255 blue level)

So black = 0, and white is 256^2*255 + 256*255 + 255. You can cobble together highlighted sentences using this technique by aligning multiple JLabel objects in the figure.

#2 CommentByYair AltmanOn May 29, 2010 @ 11:12@Nick – JLabel’s

BackgroundandForegroundproperties, and their correspondinggetXYZ(),setXYZ()accessor methods, are common to all Java Swing components, together with several other basic properties (and their accessor methods).In this particular case, java.awt.Color can be constructed in several ways:

1)

Color(int)– the single integer RGB value you have reported in your comment2)

Color(float,float,float)– accepts three values between 0.0-1.0 (R,G,B)3)

Color(float,float,float,float)– as #2 above, with an additional 0.0-1.0 value for transparency (alpha)4)

Color(int, int, int)– as #2 above but the RGB values are specified as integer values between 0-255. There is also a fourth value for alpha, as in #3 above5)

Color.redetc. – there are several predefined static values: black, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white, and yellow#3 CommentByJerryOn March 8, 2013 @ 10:16I have little or no expereience with Java, but lots with MATLAB in general. When generating analysis reports, it’s common for me to have a text box or annotation box on a plot in a figure window. I would like to insert a hyperlink in the text box (the link would lead to the the test plan responsible for generating the data in the plot). When the figure with the plot and annotation is generated, it is typically printed to a PDF so that those who might be reading the report only need adobe and not a license of MATLAB.

So,

1) how is a hyperlink inserted into an annotation box on a figure? …

2) … such that when it is printed (or saved) to PDF, the link is still a valid hyperlink in the PDF?

Thanks

#4 CommentByYair AltmanOn March 9, 2013 @ 17:06@Jerry – You can link text items to Matlab callbacks in the normal manner, by setting the handle’s callbacks (e.g.,

ButtonDownFcn). However, this does not get propagated to PDF output.#5 CommentByMBOn July 21, 2015 @ 06:00How can you implement this feature into an uicontrol? I use the GUI Layout Toolbox and this is the code:

where string is supposed to be the text from [hcomponent,hcontainer]

Thanks.

#6 CommentByYair AltmanOn July 21, 2015 @ 08:46@Miguel – simply set your

`handles.a`

button’sStringproperty value to`labelStr`

#7 CommentByMaciekOn October 30, 2015 @ 07:44When i put this code into my m-file and i run my GUI, the only inscription which I can see is “bold”, where I made a mistake ?

#8 CommentByAlexOn November 9, 2015 @ 07:06Because author forgot the closing </i> tag, obviously.

#9 CommentByYair AltmanOn November 9, 2015 @ 07:14@Alex – closing tags are not necessary in HTML labels used in Matlab (or Java Swing in general).

The reason that @Maciek doesn’t see the red “label” word is because his component is simply too narrow. When the container is too narrow, HTML simply truncates the extra text. If you increase the component width from 40 pixels to 100 pixels, you will see the entire text nicely.

#10 CommentByAlexOn November 9, 2015 @ 07:20My question is probably stupid, but where I should actually place the code, mentioned in article? The GUI.m file has several different functions and I’m not sure what all of them do (except callbacks), because of my small experience with matlab gui (started today).

#11 CommentByYair AltmanOn November 9, 2015 @ 07:23@Alex – this blog handles advanced topics that are quite often beyond the basics. You obviously need to learn the basics first. You can

^{[12]}or^{[13]}.#12 CommentByAlexOn November 9, 2015 @ 07:37Okay, thanks for the advice, Yair.