Path: news.mathworks.com!not-for-mail
From: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Enlarging size of toolbars
Date: Wed, 27 Feb 2008 22:52:01 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 42
Message-ID: <fq4pih$s8e$1@fred.mathworks.com>
References: <31128702.1203057471171.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1204152721 28942 172.30.248.37 (27 Feb 2008 22:52:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 27 Feb 2008 22:52:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: news.mathworks.com comp.soft-sys.matlab:454173


As Per suggested, this can be done with Java. Note that the
following is undocumented, unsupported, and may fail in
future Matlab versions.

First, let's enlarge the toolbar height from its default 25
pixels to 50:

hToolbar = findall(gcf,'tag','FigureToolBar');
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jToolbar.setPreferredSize(java.awt.Dimension(10,50));
jToolbar.revalidate;  % refresh/update the displayed toolbar

Now let's add a 32x32 button:

icon = [matlabroot '/toolbox/matlab/icons/warning.gif'];
[cdata,map] = imread(icon);
cdata = ind2rgb(cdata,map);
hButton =
uipushtool(hToolbar,'cdata',cdata,'tooltip','Warning');

Initially the button is cropped by Matlab to 23x23, but we
can modify the maximum size and everything now looks perfect
(modify the width from 35 if you wish wider margins between
buttons):

% The requested button is the last component in the toolbar
numButtons = jToolbar.getComponentCount;
newSize = java.awt.Dimension(35,50);
% Remember that Java indexes start at 0, not 1...
jToolbar.getComponent(numButtons-1).setMaximumSize(newSize);
jToolbar.revalidate;

As an alternative to using Matlab's uipushtool/uitoggletool,
you can always add JComponents directly into jToolbar. This
is also how you can add dropdowns (javax.swing.JComboBox),
checkboxes etc., which cannot be added to the toolbar in
plain-vanilla Matlab.

Yair Altman
http://ymasoftware.com
http://undocumented-matlab.com