Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Enlarging size of toolbars

Subject: Enlarging size of toolbars

From: Andrea Tagliasacchi

Date: 15 Feb, 2008 06:36:53

Message: 1 of 12

Hello there, I am trying to build a complete GUI system
in MATLAB. One of the few issues remaining right now is the fact that I cannot change the size of a toolbar.

For example:
set( gcf, 'ToolBar', 'none' ); % remove standard figure toolbar
h_toolbar = uitoolbar( gcf ); % create a new one
icon = imread('./icons/X.bmp');
uitoggletool(h_toolbar,'CData',icon,'TooltipString','Show Axes','ClickedCallback', @show_axes_callback, 'state', 'off');

This series of commands remove the standard toolbar and replace it with my own. X.bmp contains a 16x16 pixel image. If I feed a larger image for the button, the button does not scale!! the size of the button remains 16x16.

Is there a way of enlarging their size?
They are really, really small for anything sophisticated.

Thanks, Andrea

Subject: Enlarging size of toolbars

From: Vihang Patil

Date: 15 Feb, 2008 08:16:04

Message: 2 of 12

Andrea Tagliasacchi <public.andrea.tagliasacchi@gmail.com>
wrote in message
<31128702.1203057471171.JavaMail.jakarta@nitrogen.mathforum
.org>...
> Hello there, I am trying to build a complete GUI system
> in MATLAB. One of the few issues remaining right now is
the fact that I cannot change the size of a toolbar.
>
> For example:
> set( gcf, 'ToolBar', 'none' ); % remove standard figure
toolbar
> h_toolbar = uitoolbar( gcf ); % create a new one
> icon = imread('./icons/X.bmp');
> uitoggletool
(h_toolbar,'CData',icon,'TooltipString','Show
Axes','ClickedCallback',
@show_axes_callback, 'state', 'off');
>
> This series of commands remove the standard toolbar and
replace it with my own. X.bmp contains a 16x16 pixel
image. If I feed a larger image for the button, the button
does not scale!! the size of the button remains 16x16.
>
> Is there a way of enlarging their size?
> They are really, really small for anything
sophisticated.
>
> Thanks, Andrea


This probably might be of interest to you

http://www.mathworks.com/matlabcentral/fileexchange/loadFil
e.do?objectId=2384&objectType=file

HTH
Vihang

Subject: Enlarging size of toolbars

From: Andrea Tagliasacchi

Date: 17 Feb, 2008 19:33:02

Message: 3 of 12

> This probably might be of interest to you
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFil
> e.do?objectId=2384&objectType=file
>
> HTH
> Vihang

Thanks Vihang, I checked out your solution but I got the
same problem. The icons that are used in that GUI are bigger
than 14x14 and for some weird reason they are not displayed
correctly in my machine.
If the icons is I then only I(1:14,1:14) is displayed.

Thanks, Andrea

Subject: Enlarging size of toolbars

From: per isakson

Date: 17 Feb, 2008 20:38:01

Message: 4 of 12

"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in
message <fpa25d$rbt$1@fred.mathworks.com>...
> > This probably might be of interest to you
> >
> >
http://www.mathworks.com/matlabcentral/fileexchange/loadFil
> > e.do?objectId=2384&objectType=file
> >
> > HTH
> > Vihang
>
> Thanks Vihang, I checked out your solution but I got the
> same problem. The icons that are used in that GUI are
bigger
> than 14x14 and for some weird reason they are not
displayed
> correctly in my machine.
> If the icons is I then only I(1:14,1:14) is displayed.
>
> Thanks, Andrea
>

Not weird, but the way Matlab is made. Doc says:

"If your CData array is larger than 16 in the first or
second dimension, it may be clipped or cause other
undesirable effects. If the array is clipped, only the
center 16-by-16 part of the array is used."

Some Java might help.

/ per

Subject: Enlarging size of toolbars

From: Andrea Tagliasacchi

Date: 18 Feb, 2008 03:43:03

Message: 5 of 12

> Not weird, but the way Matlab is made. Doc says:
>
> "If your CData array is larger than 16 in the first or
> second dimension, it may be clipped or cause other
> undesirable effects. If the array is clipped, only the
> center 16-by-16 part of the array is used."
>
> Some Java might help.
>
> / per

Hi Per,

Yeah, I remember seeing that in the documentation.
Nevertheless if you check out the link that the previous guy
pointed out:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=2384&objectType=file

you will see that in the snapshots, toolbar size is resized
accordingly to the icons. The weird thing is that when I
execute that specific application on my machine, on the
other hand, I get the 16x16 cropping behavior.

The question is: Why MathWorks put that constraint on size
of toolbar icons? Is there any way of changing this behavior?

--
Andrea

Subject: Enlarging size of toolbars

From: per isakson

Date: 18 Feb, 2008 15:25:03

Message: 6 of 12

"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in
message <fpaus7$pbe$1@fred.mathworks.com>...
> > Not weird, but the way Matlab is made. Doc says:
> >
> > "If your CData array is larger than 16 in the first or
> > second dimension, it may be clipped or cause other
> > undesirable effects. If the array is clipped, only the
> > center 16-by-16 part of the array is used."
> >
> > Some Java might help.
> >
> > / per
>
> Hi Per,
>
> Yeah, I remember seeing that in the documentation.
> Nevertheless if you check out the link that the previous
guy
> pointed out:
>
>
http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=2384&objectType=file
>
> you will see that in the snapshots, toolbar size is
resized
> accordingly to the icons. The weird thing is that when I
> execute that specific application on my machine, on the
> other hand, I get the 16x16 cropping behavior.
>
> The question is: Why MathWorks put that constraint on size
> of toolbar icons? Is there any way of changing this
behavior?
>
> --
> Andrea
>

There are two versions in the submission. The icon bitmaps
are 36x36. The icons are cropped with both versions on my
system, R2007a &WinXP. The code was submitted in 2003 and
upgraded in 2003. There is an "Editor's Note:" on
compatibility problems.

With Matlab it happens that "undocumented features" are
removed in later versions.

/ per

Subject: Enlarging size of toolbars

From: Andrea Tagliasacchi

Date: 27 Feb, 2008 20:36:02

Message: 7 of 12

> With Matlab it happens that "undocumented features" are
> removed in later versions.
>
> / per

Hi Per,

Do you know if it is possible to request it as feature in
a feature request form or something?

Thanks

Subject: Enlarging size of toolbars

From: Steven Lord

Date: 27 Feb, 2008 20:40:25

Message: 8 of 12


"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in message
news:fq4hji$kbk$1@fred.mathworks.com...
>> With Matlab it happens that "undocumented features" are
>> removed in later versions.
>>
>> / per
>
> Hi Per,
>
> Do you know if it is possible to request it as feature in
> a feature request form or something?

Yes, there is. Use the form on the Contact Us page linked from the top of
pages on the MathWorks website:

http://www.mathworks.com/company/aboutus/contact_us/

Use the link under Product Feedback and select Technical Support on the next
page that comes up when you use the link.

--
Steve Lord
slord@mathworks.com

Subject: Enlarging size of toolbars

From: Yair Altman

Date: 27 Feb, 2008 22:52:01

Message: 9 of 12

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

Subject: Enlarging size of toolbars

From: Vihang Patil

Date: 28 Feb, 2008 10:27:03

Message: 10 of 12

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in
message <fq4pih$s8e$1@fred.mathworks.com>...
> As Per suggested, this can be done with Java. Note that
the
> following is undocumented, unsupported,
>
> Yair Altman
> http://ymasoftware.com
> http://undocumented-matlab.com

NICE!!!
I officially declare you KING of JAVA!!
Regards
Vihang

Subject: Enlarging size of toolbars

From: Andrea Tagliasacchi

Date: 29 Feb, 2008 01:16:08

Message: 11 of 12

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> As Per suggested, this can be done with Java. Note that the
> following is undocumented, unsupported, and may fail in
> future Matlab versions.

[....]

> As an alternative to using Matlab's uipushtool/uitoggletool,
> you can always add JComponents directly into jToolbar.

Hello Yair, you described to me two solutions, the first
accessing the java structure behind uipushtool, the second
adding directly JComponents into the toolbar.

Are both of them undocumented (thus unreliable) or adding
objects to jToolbar is a somehow safer solution? Also, this
would work only in recent MATLAB releases if I am not wrong,
since when the standard GUI has been implemented in JAVA, right?

Thanks,
Andrea

Subject: Enlarging size of toolbars

From: Yair Altman

Date: 29 Feb, 2008 15:14:02

Message: 12 of 12

"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote
> [....]
>
> Hello Yair, you described to me two solutions, the first
> accessing the java structure behind uipushtool, the second
> adding directly JComponents into the toolbar.
>
> Are both of them undocumented (thus unreliable) or adding
> objects to jToolbar is a somehow safer solution? Also, this
> would work only in recent MATLAB releases if I am not wrong,
> since when the standard GUI has been implemented in JAVA,
right?
>
> Thanks,
> Andrea

Undocumented does NOT necessarily mean unreliable - it
simply means that you cannot expect it to be bug-free, nor
to be maintained in a future Matlab version (although it
might). As long as it works in your specific Matlab
installation and you don't need to worry about distribution
to clients etc., then it shouldn't worry you.

Java has been around since Matlab 6, ages ago. The best way
to check your specific case is to type the commands I
specified into your Command Window - if it works then you're
all set. That's all there is to it - no need for any paranoia...

Finally, you're mixing things up: My entire post uses the
undocumented jToolbar - using JComponents is simply a
variation of the basic solution that I presented. If you're
not proficient in Java then the variation is probably not
for you.

Yair

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us