Add a custom JToolbar to the new toolstrip in R2012b

2 views (last 30 days)
Malcolm Lidierth
Malcolm Lidierth on 15 Sep 2012
EDIT: A supported way to do this is with the Quick Access Toolbar: see Loren's blog http://blogs.mathworks.com/loren/ for 19th September 2012.
For those that want it, here's a quick way to add custom functions to the tool strip using a JToolbar.
Improvements welcome (and probably needed) so post them in.
Run:
customToolbar.setup()
then add buttons using
customToolbar.add(mylabel, callback)
customToolbar.add(mylabel, callback, tooltip)
customToolbar.add(pathtoMyIcon, callback)
customToolbar.add(pathtoMyIcon, callback, tooltip)
Classdef:
classdef customToolbar
properties (Constant)
toolbar=javax.swing.JToolBar();
end
methods(Static)
function setup()
panel=javaObjectEDT(javax.swing.JPanel(java.awt.BorderLayout()));
customToolbar.toolbar.setPreferredSize(java.awt.Dimension(300,20));
panel.add(customToolbar.toolbar, java.awt.BorderLayout.NORTH); com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame().getToolstrip().addActionsPanel(customToolbar.toolbar);
end
function button=add(imageFile, callback, toolTip)
if isempty(dir(imageFile))
icon=imageFile;
else
icon=javax.swing.ImageIcon(imageFile);
end
button=javax.swing.JButton(icon);
button.setSize(java.awt.Dimension(20,20));
customToolbar.toolbar.add(button);
button=handle(button,'callbackproperties');
set(button, 'MouseClickedCallback', callback);
if nargin==4
button.setToolTipText(toolTip);
end
end
end
end
  1 Comment
Yair Altman
Yair Altman on 15 Sep 2012
expect to be plagiarized soon on UndocumentedMatlab.com ... :-)

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!