Add a custom JToolbar to the new toolstrip in R2012b

2 Ansichten (letzte 30 Tage)
Malcolm Lidierth
Malcolm Lidierth am 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 Kommentar
Yair Altman
Yair Altman am 15 Sep. 2012
expect to be plagiarized soon on UndocumentedMatlab.com ... :-)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by