JProgressBar.foreground doesn't work like in Ignition 7

Good afternoon.

In Ignition 7.9.9, in a “PowerTable”, you can use “JProgressBar” class to draw a progress bar in a cell.
The “foreground” property is the color of the progress bar:

In Ignition 8.0.6, in a “PowerTable”, also you can use “JProgressBar” class to draw a progress bar in a cell, but the “foreground” property is the color of the font:

  • Ignition 8 (Power Table):

image

  • Ignition 8 (configureCell event), the same code:

So how can I set the color of the progress bar?

Best Regards.

Good afternoon.

Any help?

See if any of these properties work. It seems there are some progress bar related properties: http://www.javasoft.de/synthetica/customize/

1 Like

It does not work.

Any update on this, I have the same problem with Ignition 8, where it change the color of the text not the progress bar :frowning:

What version are you on? In 8.1.6 we updated the look and feel, so while the ‘foreground color’ property controls the appearance of the progress bar, there’s a separate text property color available.

Hello @PGriffith, I am using 8.1.11 and I am running into the same issue

foreground and background changes the colors of the progress bar

So what is the property that is use for the text in order to change the color?

thanks

image
The text color property.

image

My power table does not have that option and I am on version 8.1.11 (b2021101912), do I need to check something to show that option?

Oh, my bad, I didn’t read the topic fully. Let me look into how you’d do this, I’m pretty sure it’s possible.

@ricardo.ortolani are you creating your own JProgressBar in configureCell like @informatica is?

If so, you can putClientProperty("Synthetica.progressBar.textColor", textColor) in that script and the color you select should be respected.

For the power table, you need to do something like the following:

add this code to the initialize function of your power table

	from javax.swing import JProgressBar, UIManager
	from java.awt import Color, Font
	
	self.putClientProperty("JProgressBar", JProgressBar)
	self.putClientProperty("UIManager", UIManager)
	self.putClientProperty("Color", Color)
	self.putClientProperty("Font", Font)	

In configureCell you need to use code to change the textColor depending on whatever criteria you want:

	JProgressBar = self.getClientProperty("JProgressBar")
	UIManager = self.getClientProperty("UIManager")
	Color = self.getClientProperty("Color")
	Font = self.getClientProperty("Font")

	if colIndex == 1:
		pb = JProgressBar(0, 100)
	
		pb.foreground = Color.ORANGE
		
		if value < 30:
			UIManager.put("Synthetica.progressBar.textColor", Color.RED);
		elif value < 70:
			UIManager.put("Synthetica.progressBar.textColor", Color.YELLOW);
		else:
			UIManager.put("Synthetica.progressBar.textColor", Color.GREEN);
		pb.setValue(value)
		
		pb.setString(str(value))
		
		pb.setStringPainted(True)
		
		pb.setFont(Font("Dialog", 1, 12))
		
		return {'renderer': pb}

result:
image

2 Likes

You shouldn’t need to go through UIManager for this. Something like this entirely in configureCell should work:

	from javax.swing import JProgressBar
	from java.awt import Color

	def setTextColor(bar, color):
		bar.putClientProperty("Synthetica.progressBar.textColor", color)

	if colIndex == 1:
		pb = JProgressBar(0, 100)
		pb.foreground = Color.ORANGE
		
		if value < 30:
			setTextColor(pb, Color.RED)
		elif value < 70:
			setTextColor(pb, Color.YELLOW)
		else:
			setTextColor(pb, Color.GREEN)
		pb.value = value
		pb.string = str(value)
		pb.stringPainted = True
		pb.font = Font("Dialog", 1, 12)
		
		return {'renderer': pb}

For efficiency, you can cache the JProgressBar you create in client props, but it’s probably not necessary.

1 Like

Interesting! I didn't realize you could do this directly without UIManager

There’s no strict conventions for styling components in Swing. Every look and feel does things somewhat differently once you get into the nitty gritty; usually UIManager keys cover defaults and high-level operations, but client properties are common for overriding individual component values.