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

15 次查看(过去 30 天)
In 2016a waitbar had red color with discrete marks. Older version is continuous green bar.
How to set the waitbar to the old fashion?

采纳的回答

Walter Roberson
Walter Roberson 2016-7-1
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 个评论
Walter Roberson
Walter Roberson 2016-10-1
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 2016-10-3
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.

请先登录,再进行评论。

更多回答(2 个)

Stalin Samuel
Stalin Samuel 2016-7-1
waitbar color related Discussion

John
John 2016-7-1

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by