How do I change the icon in the titlebar of a popup window?
Using the visionWindowOpened event handler...
For a main desktop, I do it this way:
from javax.swing import SwingUtilities, JFrame
from com.inductiveautomation.ignition.client.images import ImageLoader
icon = ImageLoader.getInstance().loadImage("Path/To/someImage.png")
jframe = SwingUtilities.getAncestorOfClass(JFrame, event.source)
jframe.setIconImage(icon)
For a popup window, I do it like this:
from com.inductiveautomation.ignition.client.images import ImageLoader
from javax.swing import ImageIcon
icon = ImageIcon(ImageLoader.getInstance().loadImage("Path/To/someImage.png"))
event.source.titleBar.getComponent(0).setIcon(icon)
3 Likes
Adding a re-scaling part to the solution, in case other people would need it as well.
from com.inductiveautomation.ignition.client.images import ImageLoader
from javax.swing import ImageIcon
from java.awt import Image
# Load image
loaded_image = ImageLoader.getInstance().loadImage("Path/To/someImage.png")
# Scale image
width = 23
height = 23
scaledImage = loaded_image.getScaledInstance(width,height,Image.SCALE_SMOOTH)
# Convert to Icon
icon = ImageIcon(scaledImage)
# Set icon propertie to new icon
event.source.titleBar.getComponent(0).setIcon(icon)