waitbar color, 2016a is broken red; how to set to older continuous green?

6 views (last 30 days)
In 2016a waitbar had red color with discrete marks. Older version is continuous green bar.
How to set the waitbar to the old fashion?

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jul 2016
waitbar() creates a figure. In R2016a (did not check other HG2 implementations), that figure has a hidden member in Children which is a JavaWrapper . That JavaWrapper has a JavaPeer which is a javax.swing.JProgressBar which is what is doing the real work. There is no foreground color property above that level.
I have difficulty chasing below that level as I am not very familiar with Java. On my system if I use getForeground on the JavaPeer then the result is java.awt.Color[r=255,g=0,b=0] which would be full red -- but in fact on my system, OS-X El Capitan, the actual color for my progress bars is blue. I can construct a new color and use setForeground on the JavaPeer but it makes no difference. If I use getGraphics on the JavaPeer, and getColor on the result of that, I get told java.awt.SystemColor[i=9] but I have not been able to figure out how the i=9 translates into colors. Meanwhile getBackground on the getGraphics replies with com.apple.laf.AquaImageFactory$SystemColorProxy[r=238,g=238,b=238] which is plausible for the background I observe.
  3 Comments
Walter Roberson
Walter Roberson on 1 Oct 2016
I have not yet been able to figure out how to set the foreground color, but to set the background color:
wb = waitbar(0, 'some message');
wbc = allchild(wb); %you need to get at a hidden child
wbc(1).JavaPeer.setBackground( wbc(1).JavaPeer.getBackground.YELLOW )
The inner expression there about getting the background is just an expression to get at some java.awt.Color, as java.awt.Color objects have some methods for selecting colors. Those methods return new java.awt.Color object, which you then pass in to setBackground
There is a setForeground, but even armed with the hint from Stackoverflow that one needs to setStringPainted(true), I have not been able to change the foreground color on my OS-X system. It might work on other systems. You could try
wbc(1).JavaPeer.setForeground( wbc(1).JavaPeer.getBackground.GREEN )
and you might need to add
wbc(1).JavaPeer.setStringPainted(true)
It doesn't work for me, but it might work for you.
Walter Roberson
Walter Roberson on 3 Oct 2016
In R2016b on Windows 10, the default foreground color is green.
When I used the lines shown above, I was not able to change the background color (which I was able to change on OS-X.) On the other hand, I could then do
wbc(1).JavaPeer.setForeground( wbc(1).JavaPeer.getBackground.cyan )
wbc(1).JavaPeer.setStringPainted(true)
to end up with the foreground being cyan (where-as on OS-X I was not able to change the foreground.)
The setStringPainted was important: when it is false, the default color is used.

Sign in to comment.

More Answers (2)

Stalin Samuel
Stalin Samuel on 1 Jul 2016
waitbar color related Discussion

John
John on 1 Jul 2016

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!