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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by