Thread Subject: Question about "listbox"

Subject: Question about "listbox"

From: Michael

Date: 14 Jul, 2008 17:43:02

Message: 1 of 6

I created a simple GUI with GUIDE. It includes a listbox
and a pushbutton. If I start the GUI every time the first
element of the listbox seems to be selected. It seems so
because the first element is marked blue.
If I click on the pushbutton I see that nothing is
selected because the mark does not change its colour. If I
really select something in the listbox (with clicking on
it) and then pressing the pushbutton the mark changes its
colour to grey.

All what I want is to see the grey mark when starting the
GUI that everybody "sees" that nothing is selected. Does
anybody know how can I do this?

Subject: Question about

From: us

Date: 14 Jul, 2008 18:02:02

Message: 2 of 6

"Michael ":
<SNIP startup in gray...

one of the solutions

     uh=uicontrol(...
          'units','normalized',...
          'position',[.1,.1,.8,.8],...
          'style','listbox',...
          'string',{'a';'bb';'ccc'},...
          'selectionhighlight','off');

us

Subject: Question about

From: Matt Fig

Date: 14 Jul, 2008 19:02:01

Message: 3 of 6

US does give a good solution, but sometimes this might be
more appropriate:


uh=uicontrol(...
          'units','normalized',...
          'position',[.1,.7,.8,.26],...
          'style','listbox',...
          'fontsize',16,...
          'string',{'';'a';'bb';'ccc'});


Of course you will have to deal with the fact that the user
could leave the selection set to the empty value in the
callback. Maybe a default value or whatever.

Subject: Question about

From: Michael

Date: 15 Jul, 2008 07:55:04

Message: 4 of 6

Thank you for your answers but my problem is not as easy
at it seems to be. As I mentioned I have further
uicontrols in my GUI.
I expand the example of US:
uh=uicontrol(...
             'units','normalized',...
             'position',[.1,.1,.4,.4],...
             'style','listbox',...
             'string',{'a';'bb';'ccc'},...
             'selectionhighlight','off');

... that's ok, that looks what I want...
Now I add a pushbutton to the figure:
uh=uicontrol(gcf,...
             'units','normalized',...
             'position',[.6,.6,.1,.1],...
             'style','pushbutton',...
             'string','Click me');
It still looks ok.
But if I change the order of these 2 commands - first
create the pushbutton and then the listbox then I have the
situation I described.
It seems that the order of these commands is important for
that what I want. Unfortunately I created my GUI with
GUIDE so I have no influence to the order of processing
and additionally I have 2 listboxes in real that means
there is no order of processing which gives the correct
result.

Subject: Question about

From: us

Date: 15 Jul, 2008 09:02:58

Message: 5 of 6

"Michael ":
<SNIP moving the focus...

one of the solutions

% the controls
     uh=nan(2,1);
     uh(1)=uicontrol(...
           'units','normalized',...
           'position',[.6,.6,.1,.1],...
           'style','pushbutton',...
           'string','click');
     uh(2)=uicontrol(...
           'units','normalized',...
           'position',[.1,.1,.4,.4],...
           'style','listbox',...
           'string',{'a';'bb';'ccc'});
% - actively change the focus away from #2...
     uicontrol(uh(2)); % <- focus #2
     uicontrol(uh(1)); % <- focus #1
     shg;

us

Subject: Question about

From: Michael

Date: 15 Jul, 2008 17:06:02

Message: 6 of 6

Thanks a lot...
... problem was as easy as it looked like ...

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
guide Michael 14 Jul, 2008 13:45:20
listbox Michael 14 Jul, 2008 13:45:20
rssFeed for this Thread

Contact us at files@mathworks.com