Change Icon in GWindow in G4P?

Hi Peter,

Was wondering if there’s a way to swap out the GWindow icon on the upper left corner of new GWindows?

Spent a couple hours researching and experimenting before posting here. I found one old post where you gave a hint about it but was unable to implement it. Perhaps your advice on that thread was for an older version of processing.

In any case, is this still possible? I’ve got my app mostly completed in no small part thanks to your incredible support, and I’ve got the main icon for the app switched out, but all the GWindows I’m using show the processing blue arrow instead, which looks tacky.

Ideally I’d even like to be able to suppress that icon, or jury-rig it with a transparent GIF or PNG so there’s no icon there at all, but some level of control would be nice

Thanks for your thoughts.

Mike

Can’t comment on that post would need to see it.

A GWindow is effectively a separate Processing window created on the main sketch thread so the window frame type and therefore decoration depends on the window type

  • JAVA2D - JFrame (windowed) control
  • P2D/P3D - OpenGL window

We have the secondary complication that these are further dependent on the OS. The image below shows the main sketch window (left) and GWindow (right) from the Mandelbrot example that comes with G4P as presented on an iMac. Notice the lack of border title icon.

I assume you will be exporting your app for Windows, osx and Linux vesrsions in which this will pose problems.

It might be possible to apply the same technique for GWindow, how did you do it? Even so it might only be applicable to Windows OS.

2 Likes

Thank you Peter, helpful as always.

The post was this one.

The way I changed the app icon itself for Windows on exporting the app for Windows was to use a combination of the following:

  1. Declare an image var as global before setup: PImage appIcon;
  2. Within setup, I added the following, cobbled from other sources. Not sure if the noLoop() is even necessary; haven’t tested extensively:
noLoop();
appIcon = loadImage("appIcon.png");
surface.setIcon(appIcon);
loop();

When exporting the app for Windows x64, it shows the appIcon when you double click it in the upper left corner, and also in the taskbar.

It does not change the windows icon itself - I’m using ResourceHacker or something like that to do that.

But it does not affect the GWindows. I tried using something like this for the GWindows but could never get it working right.

If it worked, I assume a transparent GIF or PNG would show nothing?

In any case, if you have any ideas, I’d be grateful.

Thanks for your time,

Mike

I am not sure what I am going to suggest will work because I use an iMac and as stated previously osx does not seem to display app icons.

At some point you create a window with some statement like this

window.GWindow.get(...);

You might try

window.GWindow.get(...);
PImage appIcon = loadImage("appIcon.png"); // If not already loaded
window.surface.setIcon(appIcon);

BTW the noLoop() and loop() are not needed to change the app icon

1 Like

Thank you Peter. I’m on a Mac too - but the app is going to be for Mac, Win, and Linux, so I need to figure out how it will work on the other platforms.

I really appreciate your time.

The appIcon image was already loaded, so I did the following per your suggestion above:

msgBox =  GWindow.getWindow(this, strTitle, width/2 + 120, height/2 + 65, windowWidth, windowHeight, JAVA2D);
msgBox.surface.setIcon(appIcon);

But I get an error in the Processing app:


Screenshot 2024-07-18 at 8.29.28 AM

Maybe there’s another library I need to load?

Thanks for your thoughts.

Mike

try

msgBox.getSurface().setIcon(appIcon);
3 Likes

By George he’s got it! Fan-freaking-tastic!

Not only did it work with the app icon, but I made a transparent PNG and it shows a blank there too! Just what I wanted!

Peter, you’re a national treasure. I really appreciate your brilliance and your support.

Thank you so much!!!

Mike