Skip to main content
Inspiring
March 7, 2025
Question

UI change icon button image

  • March 7, 2025
  • 1 reply
  • 250 views

Hi, I am writing a UI that can have a user put in a row and column amount that is generated within the UI on the fly, then passing each new icon button into a function that assigns a task to it. The task is to then allow a dialog to open upon 'OnClick' that allows the user to select a required design to be assigned to that part of the grid. Once the design is chosen I want the icon button image to update to give a visual representation of that design i.e. a star, a hat, a bell etc.

Does anyone know how to update an image within an icon button?


I have tried all sorts with the likes of drawImage(), newImage() etc. but just no joy. Examples of some of the things I have tried below but can't seem to get it to work:

iconbutton1.image = iconbutton1.newImage(File.decode(iconbutton1_imgStringNEW));
iconbutton1.graphics.drawImage(iconbutton1.image = newImage(File.decode(iconbutton1_imgStringNEW)),0,0);

 Any help would be greatly appreciated. Thanks in advance.

1 reply

glibshaftAuthor
Inspiring
March 10, 2025

I am still struggling with this but have got around it by adding each button to an individual group and upon wanting to change the image I am removing the old Icon Button and replaceing it with a new one that then inherits the new image string, this is then psased back into the function that reassigns the task to allow it to be clicked and a different image slected later, if needed.

If anyone does have the answer for how to change the image on an Icon Button that already exists, it would be greatly appreciated as it could save me a lot of time and cosing. thanks.

Participant
July 9, 2025

Hi! You can assign the decoded file directly to the image property like this:

iconbutton1.image = File.decode(iconbutton1_imgStringNEW);


Alternative, you can work with image paths like in the following example:

function ImageFromFile(imagePath) {
    var imageFile = new File(imagePath);
    if (imageFile.exists) {
        try {
            var uiImage = ScriptUI.newImage(imageFile);
            return uiImage;
        } catch (e) {
            return null;
        }
    } else {
        return null;
    }
}


var NewImage = ImageFromFile(myImagePath);
if(NewImage) { 
  
iconbutton1.image = NewImage;
}