Got Questions? Get Answers.
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:
Embedding waitbar inside a GUI

Subject: Embedding waitbar inside a GUI

From: vivek

Date: 14 May, 2007 12:16:48

Message: 1 of 13

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

Subject: Embedding waitbar inside a GUI

From: Yair Altman

Date: 14 May, 2007 13:10:22

Message: 2 of 13

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

Subject: Embedding waitbar inside a GUI

From: vivek

Date: 14 May, 2007 13:19:09

Message: 3 of 13

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

Subject: Embedding waitbar inside a GUI

From: Yair Altman

Date: 14 May, 2007 13:41:59

Message: 4 of 13

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

Subject: Embedding waitbar inside a GUI

From: K Bobane

Date: 17 May, 2007 08:10:36

Message: 5 of 13

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.

 Yair Altman wrote:
>
>
> 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

Subject: Embedding waitbar inside a GUI

From: vivek

Date: 17 May, 2007 08:48:45

Message: 6 of 13

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

Subject: Embedding waitbar inside a GUI

From: Yair Altman

Date: 17 May, 2007 09:40:54

Message: 7 of 13

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

Subject: Embedding waitbar inside a GUI

From: Yair Altman

Date: 17 May, 2007 09:58:15

Message: 8 of 13

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

Subject: Embedding waitbar inside a GUI

From: cmheath@purdue.edu

Date: 18 Jun, 2007 07:36:47

Message: 9 of 13

On May 14, 1:41 pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> 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

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

Subject: Embedding waitbar inside a GUI

From: Yair Altman

Date: 18 Jun, 2007 11:14:35

Message: 10 of 13

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

Subject: Embedding waitbar inside a GUI

From: Johannes Korsawe

Date: 17 Aug, 2007 06:32:16

Message: 11 of 13

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

Subject: Embedding waitbar inside a GUI

From: Marc O Donnagain

Date: 30 Aug, 2007 15:19:38

Message: 12 of 13

Johannes, great solution! Easy and practical, keep up the
good work

Subject: Embedding waitbar inside a GUI

From: Marc O Donnagain

Date: 30 Aug, 2007 16:37:31

Message: 13 of 13

Johannes, great solution! Easy and practical, keep up the
good work

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