From: Dani on 14 May 2010 12:20 Hi, how can one assign icons to a figures uimenu entries, the same way it is done for the Matlab desktop ->Window->Tile etc. All the menu entires have an empty space in front of them, so they are obviously prepared to have icons there, but how? Cheers Dani
From: Walter Roberson on 14 May 2010 12:26 Dani wrote: > how can one assign icons to a figures uimenu entries, the same way it > is done for the Matlab desktop ->Window->Tile etc. All the menu > entires have an empty space in front of them, so they are obviously > prepared to have icons there, but how? Is the empty space definitely for an icon, and not for showing the associated accelerator key? I note that the last example shown in the uimenu documentation is, uimenu(f,'Label','Quit','Callback','exit',... 'Separator','on','Accelerator','Q'); which is suggestive of accelerators, not of icons.
From: Dani on 17 May 2010 14:07 Hi, the accelerator key is displayed behind the menu entry, not before. There is an old newsgroup entry by Yair that states that icons can be used through java, but it looks like Matlab does not give the possibility to access this functionality. Dani On May 14, 6:26 pm, Walter Roberson <rober...(a)hushmail.com> wrote: > Dani wrote: > > how can one assign icons to a figures uimenu entries, the same way it > > is done for the Matlab desktop ->Window->Tile etc. All the menu > > entires have an empty space in front of them, so they are obviously > > prepared to have icons there, but how? > > Is the empty space definitely for an icon, and not for showing the > associated accelerator key? I note that the last example shown in the > uimenu documentation is, > > uimenu(f,'Label','Quit','Callback','exit',... > 'Separator','on','Accelerator','Q'); > > which is suggestive of accelerators, not of icons.
From: Yair Altman on 17 May 2010 20:10 Dani <dani.schmid(a)gmail.com> wrote in message <f04126c1-e45d-4908-a987-296942512e41(a)37g2000yqm.googlegroups.com>... > Hi, > > how can one assign icons to a figures uimenu entries, the same way it > is done for the Matlab desktop ->Window->Tile etc. All the menu > entires have an empty space in front of them, so they are obviously > prepared to have icons there, but how? > > Cheers > > Dani This can't be done using plain supported Matlab but it can be done using undocumented Java functionality. Matlab menus (uimenu) are basically simple wrappers for the much more powerful and flexible Java Swing JMenu and JMenuItem on which they are based. Much important functionality that is available with Java menus is missing from the Matlab uimenus, including menu icons. Let's add an icon to the Save menu item. We need a reference for the "Save" menu item. Note that unlike regular Java components, menu items are retrieved using the getMenuComponent() method, not getComponent(): % File main menu is the first main menu item => index=0 jFrame = get(handle(gcf),'JavaFrame'); jMenuBar = jFrame.fFigureClient.getMenuBar; jFileMenu = jMenuBar.getComponent(0); % Save menu item is the 5th menu item (separators included) jSave = jFileMenu.getMenuComponent(4); %Java indexes start with 0! inspect(jSave) => just to be sure: label='Save' => good! Let us now set an icon for the Save menu item. Many of Matlab's icons reside in either the [matlabroot '/toolbox/matlab/icons/'] folder or the [matlabroot '/java/jar/mwt.jar'] file (a JAR file is simply a zip file that includes java classes and resources like icon images. Let us an create icon from the latter, to keep a consistent lookand-feel with the rest of Matlab (we could just as easily use our own external icon files): % External icon file example myIcon = 'C:\Yair\save.gif'; jSave.setIcon(javax.swing.ImageIcon(myIcon)); % JAR resource example jarFile = fullfile(matlabroot,'/java/jar/mwt.jar'); iconsFolder = '/com/mathworks/mwt/resources/'; myIcon = ['jar:file:/' jarFile '!' iconsFolder 'save.gif']; myIcon = java.net.URL(myIcon); % not necessary for external files jSave.setIcon(javax.swing.ImageIcon(myIcon)); I plan to post a couple of articles on similar Matlab menu customizations on the Undocumented-Matlab blog in a few weeks, so stay tuned... Yair Altman http://UndocumentedMatlab.com
From: Matt Fig on 17 May 2010 21:34 Yair, I tried to run your example and it failed with the error: ??? Java exception occurred: java.lang.ArrayIndexOutOfBoundsException: No such child: 4 at java.awt.Container.getComponent(Unknown Source) at javax.swing.JMenu.getMenuComponent(Unknown Source) Is this due to my using 2007b? I tried looking at other (lower) indexes and the same error occurs. Thanks.
|
Next
|
Last
Pages: 1 2 Prev: Image processing: phase correlation Next: univariate bimodal distribution |