G4P Way to Create New Window Hidden?

Hi, I’m using G4P, wonderful lib! I’ve found a way to programmatically create windows and hide them - based on posts here and Peter’s fab library! All Peter’s code; works great.

What I haven’t found is a way to create a new window using the GUI Builder, and have it initially hidden.

Is this possible to do with the GUI Builder? Or maybe add some code to make it work that way? I can set it invisible immediately after creation, but it shows for a split second; but you do notice it. Not ideal.

Otherwise, I can do this all with code but I love being able to lay things out with the GUI Builder.



The short answer is no - sorry about that.

1 Like

Not a deal breaker. I can do it all in the code, a la the matrix lol.

But then I can’t use the GUI Builder to make additional windows, which is a huge bummer because it’s so great.

In any case, thank you Peter. I’m sure you have other things to do with your life than update libraries lol!


In G4P every extra window is effectively an instance of PApplet. The process of launching a PApplet will create a visible window which can be set invisible immediately but the user will still see the flash of a visible window.

So when I said “no” before it was not because I am unwilling to update my libraries but I don’t know of any possible way to avoid the window-flash. :grin:

1 Like

Forgive me if it sounded as if I was insinuating your were unwilling! Nothing could be further from the truth.

This latest version is proof that’s not true!!! You literally updated the library because I asked if you’d include a feature (well, maybe you already were going to, but that’s how it seemed).

I know that if something is possible, and feasible, you do it, if it makes sense. You’re just awesome that way :slight_smile:

So thank you!

By the way, I did try exactly that scenario, making the window then hiding it, but as you say, it flashes up for a second and doesn’t look good.

I also thought of making it, but having it off the screen initially, but can’t seem to get a large enough initial value for the window XY coordinates for it to work right.

Hmmm…I wonder if something like adding “noLoop()” when it’s created would work? Or something sneaky like that? Then adding back loop()? Have to think about it or experiment I guess.

As I said, I have “invisible” initial windows working fine through straight code, from your other generous examples here on the board.

Thanks Peter!


Interesting I didn’t manage that on my iMac, perhaps it is affected by OS.

1 Like

You did figure it out once - in a post here!

You started with this:

GWindow preferences = null;

then a button to call a void:

public void imgbtnPrefs_click(GImageButton source, GEvent event) { //_CODE_:imgbtnPrefs:965597:
  println("imgbtnPrefs - GImageButton >> GEvent." + event + " @ " + millis());
  if (preferences == null) {
  } else {
} //_CODE_:imgbtnPrefs:965597:

Then the creation…

void createPreferencesWindow() {
  preferences =  GWindow.getWindow(this, "Options", width/2 + 120, height/2 + 70, 240, 140, JAVA2D);
  preferences.addDrawHandler(this, "preferencesDraw");
  preferences.addMouseHandler(this, "preferencesMouse");
  preferences.addKeyHandler(this, "preferencesKey");
  preferences.addData(new MyData());

public void preferencesDraw(PApplet app, GWinData data){
    // Saves doing it for every variable in MyData class
    MyData myData = (MyData) data;
    //// Draw red line to last click position.
    app.line(app.width / 2, app.height/2, myData.lastClickX, myData.lastClickY);
    //// draw black line to current mouse position
    app.line(app.width / 2, app.height/2, app.mouseX, app.mouseY);
public void preferencesMouse(PApplet app, GWinData data, MouseEvent event) {
    // Saves doing it for every variable in MyData class
    MyData myData = (MyData) data;
    if(event.getAction() == MouseEvent.CLICK){
      myData.lastClickX = mouseX;
      myData.lastClickY = mouseY;

public void preferencesKey(PApplet app, GWinData data, KeyEvent event) {


public class MyData extends GWinData {
    // The variables can be anything you like.
    public int lastClickX,lastClickY;


Works great! Thanks to you and the guy who prompted the question in another post!

PS I’ve got a MacBook Pro M3…

If you can find it again can you post a link to the discussion.

1 Like

I’m trying to find it…not having any luck…

I got the whole set the window thing to null from your own example, but you probably want to see how you answered the guy…

If I find it I’ll let you know Peter…sorry at the moment…

1 Like