Add a custom JToolbar to the new toolstrip in R2012b

2 ビュー (過去 30 日間)
Malcolm Lidierth
Malcolm Lidierth 2012 年 9 月 15 日
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 件のコメント
Yair Altman
Yair Altman 2012 年 9 月 15 日
expect to be plagiarized soon on UndocumentedMatlab.com ... :-)

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by