surface.setResizable() does not work as expected in child applet using JAVA2D renderer

Hello,

i found a nasty little thing which makes some trouble.
But I don’t want to call it a bug because I don’t know where it’s coming from :wink:
It would be very helpful to me if someone could explain it.

The following works as expected. The maximize button maximizes the window.
Pressing the button again restores the previous size of the window.
This works with JAVA2D, FX2D, P2D and P3D.

void setup() {
  size(400, 400, P3D);
  surface.setResizable(true);
}
void draw() {}

Doing the same in a child Applet works for all renderers, except for JAVA2D.
The following works as expected:

class TestWindow extends PApplet {

  public TestWindow () {
    super();
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  void settings() {
    size(200, 200, FX2D);
  }

  void setup() {
    surface.setResizable(true);
  }

  void draw() {}
}

Doing the same with JAVA2D maximizes the window as it should if you press the button once.
But from now on it is impossible to restore the previous size of the window.
It stays maximized.
As you can imagine, this is very annoying.
To me the JAVA2D renderer is the only working option.

The only solution for a correct behaviour I have is using a JPanel inside a JFrame that adds the Processing Canvas to the JPanel.
But then I have to resize the surface myself and it causes the code to be unnecessarily bloated.

Does anyone have an explanation for this?
Thank you in advance!

Martin

I have added a component listener to the child Applet to see what happens during resize.

jframe = (JFrame)((processing.awt.PSurfaceAWT.SmoothCanvas)this.getSurface().getNative()).getFrame();
    jframe.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent componentEvent) {
          println("Child Applet resized " + jframe.getExtendedState());
        } //
    });

The console now shows the follwing:
During the creation of the surface there are 6 resize events with an extended state of 0 or NORMAL.
When I try to maximize the window, 3 resize events are fired, also with an extended state of 0.

Since the console is slow, I have printed the results directly to the window.
And now I saw that the extended state was MAXIMIZED_BOTH for a short time and then immediately jumped back to NORMAL.

This is the behaviour of Processing3 and Windows 10.
When i try this on Mac OS X, there is no maximize button in the title bar!
Enlarging and reducing window sizes is one of the basics of a GUI. This should also work in Processing flawlessly :angry:

Source code has to be run in Processing version 3.5.4 (I was unable to run in 4.06b due to java.lang.ClassNotFoundException:) and can verify that window does not resize on Mac and resize button is not active in title bar. Modified source code runs ok in IntelliJ. For whatever it’s worth, the window doesn’t look like a 200x200 to me, more like a 120x120; not sure setting() even works. You can set it to 800x800 and it stays the same size.

For whatever it’s worth, you can run a blank sketch in 3.5.4 and get the same result. I can’t see that your posted code does anything; the default window is displayed in 3.5.4 but the FX2D renderer also does nothing on my Mac system. Console message states: The type TestWindow is never used locally.

Yes you are right, posted source code should run.
So here is a running example:

TestWindow testWindow;

void settings() {
  size(400, 400, JAVA2D);
}

void setup() {
  surface.setResizable(true);
  testWindow = new TestWindow();
}

void draw() {
  background(0);
}

class TestWindow extends PApplet {

  public TestWindow () {
    super();
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  void settings() {
    size(200, 200, JAVA2D);
  }

  void setup() {
    surface.setResizable(true);
  }

  void draw() {
    background(255);
  }
}

And I should have posted it like this right away, because it works with the reduced code :thinking:
Thanks for the hint. Now I know that i have to look elsewhere :smile:

And it seems that something goes wrong with my LookAndFeel implementation (which is not included in the example code).
So I need to find out what’s wrong…