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:
Changing highlight color in listbox

Subject: Changing highlight color in listbox

From: Matthew C

Date: 24 Mar, 2010 13:44:05

Message: 1 of 2

I have a few list boxes in a GUI. It seems the default selection color is blue and when the list box is de-selected (clicking somewhere else), the selected text becomes gray.

Is there a way to have both of them remain blue without using "undocumented" matlab properties. Thanks in advance.

Subject: Changing highlight color in listbox

From: Yair Altman

Date: 24 Mar, 2010 18:56:20

Message: 2 of 2

"Matthew C" <matthew_lane9@hotmail.com> wrote in message <hod4v5$oh5$1@fred.mathworks.com>...
> I have a few list boxes in a GUI. It seems the default selection color is blue and when the list box is de-selected (clicking somewhere else), the selected text becomes gray.
>
> Is there a way to have both of them remain blue without using "undocumented" matlab properties. Thanks in advance.


This cannot be done using documented features. Here's the undocumented way to do it:

1. Download my FindJObj utility from the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects

2. Place the following in your Matlab code, when the focus is on the listbox:
jListbox = findjobj(hListbox);
jListbox=jListbox.getViewport.getComponent(0);
jListbox.setSelectionAppearanceReflectsFocus(0);

Note that action #2 "freezes" the current selection color, so if your listbox is not in focus when you run it, the gray selection color will remain even when the listbox is back in focus...

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