Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Change Highlight Color in uicontrol Listbox

Subject: Change Highlight Color in uicontrol Listbox

From: Jeremy Turner

Date: 30 Apr, 2009 13:05:19

Message: 1 of 2

Does anyone know of a method to programmatically change the highlight color of selected items in a list box? I have a list box with file names in a GUI, and I would like to change the highlight color for files that meet acceptance criteria. Any suggestions?

Subject: Change Highlight Color in uicontrol Listbox

From: Yair Altman

Date: 15 Aug, 2009 19:40:18

Message: 2 of 2

"Jeremy Turner" <jtiota@yahoo.com> wrote in message <gtc7me$lnc$1@fred.mathworks.com>...
> Does anyone know of a method to programmatically change the highlight color of selected items in a list box? I have a list box with file names in a GUI, and I would like to change the highlight color for files that meet acceptance criteria. Any suggestions?

You will need to use the listbox's underlying Java component to do this. This component can be retrieved using my FindJObj utility on the Matlab File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14317

Here is the code snippet:

hListbox = uicontrol('style','listbox', ...);
jScrollPane = findjobj(hListbox); % get the scroll-pane object
jListbox = jScrollPane.getViewport.getComponent(0);
set(jListbox, 'SelectionBackground',java.awt.Color.yellow); % option #1
set(jListbox, 'SelectionBackground',java.awt.Color(0.2,0.3,0.7)); % option #2

You can similarly change SelectionForeground and many other undocumented interesting properties.

For other interesting undocumented stuff you can do with listboxes, read here: http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/

Yair Altman
http://UndocumentedMatlab.com
 

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us