ImageButton Not Visible SOLVED

Hello everyone!

I am trying to use ImageButtons and have no examples to work with. We can use one as an example:

I declared in the public section of the app:
ImageButton saveImage;

I created an image just beneath that:
Image openImage = ImageCache::getFromFile(File::getCurrentWorkingDirectory().getChildFile (“save.png”));

In the constructor I used the addAndMakeVisible(saveButton) function and the code:

saveButton.setImages (false, false, false, saveImage, 1.0f, {Colour(0xff3c1818)}, saveImage, 1.0f, {Colour(0xff3c1818)}, saveImage, 1.0f, {Colour(0xff3c1818)});

I used saveButton.setBounds() function in the repaint() function of the application.

Compiles just fine and there is a space for the images but the images do not appear. What am I missing? Please help!

Probably isn’t the file path you think it is. Try an absolute path to the image file as a test.

1 Like

If it fits your use case, I would encourage you to embed the image in your project. Doing it this way allows you not to worry about file paths, as well as guarantees the image will be available at run time. Add the image to the Projucer project, and then within your code access it like this:

const auto gearImage = ImageCache::getFromMemory (BinaryData::settings_gear_black_png, BinaryData::settings_gear_black_pngSize);
3 Likes

I also noticed you having a naming and scope issue in your example:

I declared in the public section of the app:
ImageButton saveImage;

I created an image just beneath that:
Image openImage =

So, your member variable is called saveImage, but you are initializing a local variable of openImage.

2 Likes

This works. I tried it earlier but got no results because I used save_png_size instead of save_pngSize so thanks a lot! Images came out funny looking but I m sure I can work that out now they are appearing in the first place. How did you get that syntax? There aren’t any examples I could find of that.

Glad I could help. :slight_smile:

I’ve been writing JUCE, and C++, code for so long, I couldn’t tell you exactly how I derive an exact usage. Docs, experimentation, other peoples code, this forum… all of these things help me gain a better understanding of finding best usage.

1 Like