Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change Highlight Color in uicontrol Listbox

37 views
Skip to first unread message

Jeremy Turner

unread,
Apr 30, 2009, 9:05:19 AM4/30/09
to
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?

Yair Altman

unread,
Aug 15, 2009, 3:40:18 PM8/15/09
to
"Jeremy Turner" <jti...@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

0 new messages