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
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
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
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
Best regards.
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
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
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
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
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