Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embedding waitbar inside a GUI

539 views
Skip to first unread message

vivek

unread,
May 14, 2007, 12:16:48 PM5/14/07
to
hi all,

after a long struggle I have to post my problem. I'm just not able to
get the waitbar figure embedded inside a GUI i have created. The
reason being i don't want another figure to popup and hence would
like the waitbar to be displayed through my main gui.

example code:

On the gui i have created an axes and the TAG for it is
"waitbar_test". I have created a pushbutton which once pressed, a FOR
loop will be executed and the waitbar should progress accordingly.

Inside the pushbutton callback in my GUI - M code

------------------------------------------------------
%Made the axis Inactive
set(handles.waitbar_test,'HandleVisibility','ON','Visible','ON');

%Turn off all axis labeling
axis off;

for a = 1:var

waitbar(a*divi/100,handles.waitbar_test,['Please wait....testing...
- ',...
num2str(round(a*divi)),'% complete...'])

end

------------------------------------------------------

Once the GUI is run, this results in an error. Can someone please
help me out here ?? I never expected waitbar to be such a pain to
embed inside a GUI

Yair Altman

unread,
May 14, 2007, 1:10:22 PM5/14/07
to
To embed a scrollbar in a figure I suggest 2 alternatives:

1. Use statusbar from the File Exchange ( <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14773>
to display a block-style or continuous progress bar at the bottom of
the figure (the statusbar area).

2. Embed a javax.swing.JProgressBar using either Matlab's built-in
javacomponent or the File Exchange's uicomponent. Here's a skeleton:

jPb = javax.swing.JProgressBar;
set(jPb,'StringPainted',1,'Value',12.5,'Indeterminate',0);
% Note: use the default 'StringPainted'=0 for block-style progress,
and 'StringPainted'=1 for continuous style.
[hPb, hContainer] = javacomponent(jPb,position,gcf);

for index = 1 : numLoops
% do whatever...
set(hPb,'Value',index/numLoops);
end

Yair Altman

vivek

unread,
May 14, 2007, 1:19:09 PM5/14/07
to
Thanks for your reply Yair.

I was tempted to use the java component. I entered the commands as
you wrote, should that have worked ?

Did i need to do something on my GUI to make java component work ?
Sorry i don't know much about java and matlab.

cheers
Vivek

Yair Altman

unread,
May 14, 2007, 1:41:59 PM5/14/07
to
You don't need anything else - it should work "out of the box". One
correction, though: when you set boolean properties of the
progressbar (like 'StringPainted' and 'Indeterminate'), you need to
specify 'on' or 'off', not 0 & 1.

get(jPb) to see the current values of the progressbar properties, and
set(jPb) to see the list of settable properties.

Interesting progressbar properties are:
- Background (color)
- BorderPainted (on/off)
- Enabled (on/off)
- Foreground (color)
- Indeterminate (on/off)
- Maximum (number)
- Minimum (number)
- Orientation
- String (displayed over the continuous progress - usually 'X%')
- StringPainted (on/off) - determines block style
- ToolTipText (string)
- Value (number) - Should be: Minimum<=Value<=Maximum
- Visible (on/off)

Inside your loop, after the initial properties setup, you only need
to update the Value property, and then maybe drawnow() to refresh the
screen.

Make sure you specify valid pixel position coordinates if you use
javacomponent(). It only accepts pixels - not normalized or any other
type of units.

Yair Altman

K Bobane

unread,
May 17, 2007, 8:10:36 AM5/17/07
to
Hi,
Many thanks for the 'statusbar' utility. I wanted to do something
similar to what Vivek required, and have been able to use your
'statusbar' utility to achieve that. There is just one little thing I
would like to do, which is shift the ProgressBar (or whole statusbar)
from the left edge of the figure to the centre of the figure (or any
where else for that matter). I have tried changing the 'VisibleRect'
properties for the ProgressBar but that doesn't work. Also tried
substituting 'West' for 'East' in this line in your code:
statusbarObj.add(jProgressBar,'West');
Still no success. Am not very good with Java unfortunately. Could you
please help me with this.

Best regards.

vivek

unread,
May 17, 2007, 8:48:45 AM5/17/07
to
Hi Yair,

Thanks for the update you gave on that. The java component did work
just out of the box. But its not as flexible and good as the waitbar
which allows the user to put a custom title on top of the progress
bar.

So as of now, I have just adjusted the waitbar figure's position such
that once my GUI is launched, the waitbar when evoked will be placed
on the lower left corner of my main GUI and have made its windowstyle
to modal so that it remains as the active figure.

I was hoping to embed the original waitbar into my GUI but I guess
its not possible. The statusbar is a good utility but I guess it just
doesn't suit my need.

Thanks for help on java progressbar, i never knew that part of
MATLAB. Is it possible for you to send me a link or something where
such hidden components of MATLAB are well documented like the java PB
?

Thanks once again.

Regards
Vivek

Yair Altman

unread,
May 17, 2007, 9:40:54 AM5/17/07
to
StatusBar is not a Matlab component but something I wrote myself and
posted on the File Exchange for others to use.

JProgressBar is not a Matlab component but a Java Swing one, written
by Sun Inc. Here's a link to the documentation of this and other
Swing components: <http://java.sun.com/docs/books/tutorial/uiswing/>

Yair Altman

Yair Altman

unread,
May 17, 2007, 9:58:15 AM5/17/07
to
K Bobane wrote:
> I have tried changing the 'VisibleRect'
> properties for the ProgressBar but that doesn't work. Also tried
> substituting 'West' for 'East' in this line in your code:
> statusbarObj.add(jProgressBar,'West');

Unfortunately it's not trivial to do so. You can use 'East' but it
doesn't resize automatically (as I indicated in a comment within the
code). Basically you need to play around with the layout manager,
which is a BorderLayout in this case (hence EAST/WEST/CENTER). You
might try Box Layout, as explained in the following link, but I'm
afraid you're on your own here: <http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html>

Yair Altman

cmh...@purdue.edu

unread,
Jun 18, 2007, 10:36:47 AM6/18/07
to

I am having similar difficulty embedding the JProgressBar into a
MATLAB GUI. Particularly, I would like to resize the progress bar
making it rectangular with horizontal orientation as it currently
opens in the figure as a square but am unable to effectively use the
width and height operations to change the shape. I unfortunatley am
not at all familiar with JAVA. Any help would be greatly
appreciated. Thanks

Chris

Yair Altman

unread,
Jun 18, 2007, 11:14:35 AM6/18/07
to
cmheath wrote:
>
> I am having similar difficulty embedding the JProgressBar into a
> MATLAB GUI. Particularly, I would like to resize the progress bar
> making it rectangular with horizontal orientation as it currently
> opens in the figure as a square but am unable to effectively use
the
> width and height operations to change the shape. I unfortunatley
> am not at all familiar with JAVA. Any help would be greatly
> appreciated. Thanks
>
> Chris

You don't need to know any Java: just use javacomponent() (or
UICOMPONENT from the File Exchange) to position your component
onscreen. Then, use simple get/set commands to modify the
height/width/position or any other property. It's just like setting
properties for Matlab components.

Yair Altman

Johannes Korsawe

unread,
Aug 17, 2007, 2:32:16 AM8/17/07
to
Hi there,

i was just about the same question. I tried the JAVA
solution (not too hard) and i failed.

So i simply added another axes in my GUI (where the waitbar
was supposed to be) and called some subfunction like

function update_waitbar(handles,value)

h=handles.waitbar_axes;set(h,'Visible','On');

axes(h);cla;h=patch([0,value,value,0],[0,0,1,1],'b');

axis([0,1,0,1]);axis off;drawnow;

(value beeing a fraction between 0 and 1.)

With this, i get a nice waitbar-like behaviour which can
easily be extended by also displaying more information
about Status [%], time elapsed, time remaining etc. by
putting necessary calculations inside update_waitbar.

Best regards,

Johannes


Marc O Donnagain

unread,
Aug 30, 2007, 11:19:38 AM8/30/07
to
Johannes, great solution! Easy and practical, keep up the
good work

Marc O Donnagain

unread,
Aug 30, 2007, 12:37:31 PM8/30/07
to

Nimrod

unread,
Sep 22, 2016, 11:20:08 AM9/22/16
to
I found a much simpler solution for this problem
You just need to create a waitbar by yourself and then you can implement it inside objects of your gui..

set a bar graph in the create function of whatever axes you create in your gui
set it to have 10 empty bars (you can change the amount)

handles.waitbar = bar(1:10, zeros(1, 10));
update the handles using guidata and continue to your code

when you want to update the bars or to show progress, you can simply update the "YData" value of your bar object, and you can update it using the set command..

set(handles.waitbar, 'Ydata', [ones(1, x) zeros(1, 10-x)])
where x is the step you want to be at..

that's it.. it is simple and it works! without using JAVA.....
0 new messages