2
votes

How could I control the width of the bar inside a waitbar in Matlab R2015a?

I just referred to the following question:

waitbar -> length ot the bar figure?

It works perfectly in Matlab R2012b with the solution as the user mentioned, but for R2015a, the 'Waitbar 1' string is placed in the middle, and the percentage bar does not change width at all....

I used the following code:

HWait = waitbar(0,'Waitbar 1', 'Units', 'normalized', 'Position', [0.25 0.4 0.3 0.08]);
set(HWait,'Name','Tests running');
childrenWaitb = get(HWait, 'Children') ;
set(childrenWaitb, 'Position',[10.8000 13.5000 320 9]);
1

1 Answers

1
votes

The waitbar changed (Along with lots of graphics) in r2014b. The waitbar progress bar used to be a simple axes which allowed you to set the position of.

The new waitbar is built on a java progress bar - so you need to access undocumented features of java to update it:

% Create a progress bar.
hBar = waitbar ( 0, 'Please Wait....' );
% now use java to get to the progress bar
jFrame = get ( hBar, 'JavaFrame' ); % this will throw a warning 
jFigPanel = jFrame.getFigurePanelContainer;
% Now go down through the children of the panel to get the container for the progress bar
jContainer = jFigPanel.getComponent(0);
jPanel = jContainer.getComponent(0);
% Change the location of the panel (ref pixels)
jPanel.setLocation(0,40);
% Change the size of the panel
jPanel.setSize(360,18);
% You then need to repaint and validate for the update to be visible.
jContainer.repaint
jContainer.revalidate