Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Popup menu in the Toolbar?

Subject: Popup menu in the Toolbar?

From: jason

Date: 10 Dec, 2007 19:18:39

Message: 1 of 5

Does anyone know how to put a popup menu in a gui toolbar,
similar to the "Current Directory" popup menu on the
Matlab Desktop? currently I can only find how to add
pushbuttons and toggle buttons to it.

Thanks for any help
Jason

Subject: Popup menu in the Toolbar?

From: Matt Fig

Date: 10 Dec, 2007 20:21:12

Message: 2 of 5

"jason " <mcmains.1@osu.edu> wrote in message
<fjk3ef$sdg$1@fred.mathworks.com>...
> Does anyone know how to put a popup menu in a gui toolbar,
> similar to the "Current Directory" popup menu on the
> Matlab Desktop? currently I can only find how to add
> pushbuttons and toggle buttons to it.
>
> Thanks for any help
> Jason


I don't see in the documentation that this can be done
directly. However, you could do something quick and dirty
like this (watch for wrapping):

fg = figure('units','pixels','position',[400 500 300 300]);
posfg = get(gcf,'position');
posfrm = [1 (posfg(4)-20) posfg(3)-1 20];
fr =
uicontrol('style','frame','units','pixels','position',posfrm);
pum = uicontrol('style','popupmenu','position',posfrm-[-1 -1
200 0],...
                'string',{'here','there','everywhere'});

Subject: Popup menu in the Toolbar?

From: Yair Altman

Date: 10 Dec, 2007 22:30:34

Message: 3 of 5

"jason " <mcmains.1@osu.edu> wrote in message
<fjk3ef$sdg$1@fred.mathworks.com>...
> Does anyone know how to put a popup menu in a gui toolbar,
> similar to the "Current Directory" popup menu on the
> Matlab Desktop? currently I can only find how to add
> pushbuttons and toggle buttons to it.
>
> Thanks for any help
> Jason


As Matt said, modifying the toolbar is undocumented and
unsupported. You can easily add pushbuttons and
toggle-buttons using the following syntax:

htb = findall(gcf,'tag','FigureToolBar');
if ~isempty(htb)
   
uitoggletool('tooltip','toggle','seperator','on','parent',htb,'cdata',iconData);
    uipushtool(...); % similarly
end

However, trying the same with a uicontrol or javacomponent
is blocked. So, the workaround is to directly add a Java
dropdown
(javax.swing.JComboBox({'here','there','everywhere'})
object) to the underlying Java implementation of the
toolbar. This is slightly more difficult and requires some
Java knowledge. Use my FindJObj submission on the File
Exchange to get started:

jtb = findjobj(gcf,'-nomenu','class','mjtoolbar');
if ~isempty(jtb)
    jtb(1).addSeparator;
    jcb=javax.swing.JComboBox({'here','there','everywhere'}));
    jtb(1).add(jcb);
    jtb(1).repaint;
    jtb(1).revalidate;
end

Of course, in all events you need to set the action
callback: For pushbuttons/toggle-buttons this is via their
ClickedCallback property; for JComboBox this is via its
ActionPerformedCallback property.

Yair Altman
http://ymasoftware.com

Subject: Popup menu in the Toolbar?

From: Yair Altman

Date: 18 Dec, 2007 22:35:24

Message: 4 of 5

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fjkema$16s$1@fred.mathworks.com>...
> "jason " <mcmains.1@osu.edu> wrote in message
> <fjk3ef$sdg$1@fred.mathworks.com>...
> > Does anyone know how to put a popup menu in a gui toolbar,
> > similar to the "Current Directory" popup menu on the
> > Matlab Desktop? currently I can only find how to add
> > pushbuttons and toggle buttons to it.
> >
> > Thanks for any help
> > Jason
>
>
> As Matt said, modifying the toolbar is undocumented and
> unsupported. You can easily add pushbuttons and
> toggle-buttons using the following syntax:
>
> htb = findall(gcf,'tag','FigureToolBar');
> if ~isempty(htb)
>
>
uitoggletool('tooltip','toggle','seperator','on','parent',htb,'cdata',iconData);
> uipushtool(...); % similarly
> end
>
> However, trying the same with a uicontrol or javacomponent
> is blocked. So, the workaround is to directly add a Java
> dropdown
> (javax.swing.JComboBox({'here','there','everywhere'})
> object) to the underlying Java implementation of the
> toolbar. This is slightly more difficult and requires some
> Java knowledge. Use my FindJObj submission on the File
> Exchange to get started:
>
> jtb = findjobj(gcf,'-nomenu','class','mjtoolbar');
> if ~isempty(jtb)
> jtb(1).addSeparator;
> jcb=javax.swing.JComboBox({'here','there','everywhere'}));
> jtb(1).add(jcb);
> jtb(1).repaint;
> jtb(1).revalidate;
> end
>
> Of course, in all events you need to set the action
> callback: For pushbuttons/toggle-buttons this is via their
> ClickedCallback property; for JComboBox this is via its
> ActionPerformedCallback property.
>
> Yair Altman
> http://ymasoftware.com


I just found out that you don't need to use findjobj to find
the underlying Java toolbar jtb:

jtb = get(get(htb,'JavaContainer'),'ComponentPeer');

Yair

Subject: Popup menu in the Toolbar?

From: jason

Date: 25 Jul, 2008 19:23:02

Message: 5 of 5

Your solution worked great Yair, its a little more bulky
to program than I'm used to, but it makes the figure looks
exactly how I wanted it. Thanks!

Jason

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
undocumented Yair Altman 10 Dec, 2007 17:35:03
popup jason 10 Dec, 2007 14:20:04
menu jason 10 Dec, 2007 14:20:04
gui jason 10 Dec, 2007 14:20:04
figure jason 10 Dec, 2007 14:20:04
toolbar jason 10 Dec, 2007 14:20:04
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics