# FX2D Resizable Window Error

**URL:** https://discourse.processing.org/t/fx2d-resizable-window-error/15995
**Category:** Processing
**Created:** [November 30, 2019, 9:21pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995 "2019-11-30T21:21:35Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [November 30, 2019, 9:21pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/1 "2019-11-30T21:21:35Z")

</div>

Switching the rendering engine to FX2D has introduced a lot of absurdities that I’ve never had to deal with before, including this issue right here:

> <https://github.com/sojamo/controlp5/issues/36>
>
> Windows 7, Processing 3.0.1
> Taking a number of examples (e.g. button / slide / textfield), adding FX2D to the size() constructor consistently...

  
Which was an easy, yet unexpected, fix.  
However, another issue has come up. It seems as though setting the render engine to FX2D makes the window resizable by default. In my sketch, I would like the window to **not** be resizable. So I add this bit of code to setup():

```auto
void setup() {
  size(400, 464, FX2D);
  surface.setResizable(false);

```

Now, after adding that and running it, the sketch immediately closes with the most ambiguous error message that I have ever seen:

**handleDraw() called before finishing**  
**Could not run the sketch (Target VM failed to initialize).**  
**For more information, read revisions.txt and Help ? Troubleshooting.**

Now, if I keep all my code as it is, but change the rendering engine back to the default, this problem does not occur. I did some minimal research before posting this, but I couldn’t find this same issue in anyone else’s post. So please send help 😃

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [December 1, 2019, 7:55pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/2 "2019-12-01T19:55:10Z")

</div>

Put such code in `initSurface()` instead.

```
@Override
protected PSurface initSurface() {
    surface = super.initSurface();
    canvas = (Canvas) surface.getNative();
    scene = canvas.getScene();
    stage.setResizable(false);
    return surface;
}
```

---

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [December 1, 2019, 9:23pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/3 "2019-12-01T21:23:07Z")

</div>

Where in the code should I put this? Should I put it before or after `setup()`? Because I tried to put it before setup and I got errors for the variables `canvas`, `scene`, and `stage` saying that those variables do not exist.

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [December 1, 2019, 9:35pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/4 "2019-12-01T21:35:13Z")

</div>

Oh yeah, either define them variables in the function or outside it:

```
PSurfaceFX surface;
Canvas canvas;
Scene scene;
Stage stage;

```

You’ll have to include the relevant imports too.

---

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [December 1, 2019, 9:38pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/5 "2019-12-01T21:38:08Z")

</div>

Pardon my naiveté, but what imports would those be?

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [December 2, 2019, 7:54pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/6 "2019-12-02T19:54:21Z")

</div>

```auto
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.stage.Stage;

```

---

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [December 2, 2019, 11:06pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/7 "2019-12-02T23:06:34Z")

</div>

Pardon me if I’m mistaken, but it seems as though there should be another library to import because I’m still getting the message “The class PSurfaceFX does not exist”

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [December 3, 2019, 7:40am UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/8 "2019-12-03T07:40:49Z")

</div>

`import processing.javafx.PSurfaceFX;`

---

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [December 3, 2019, 4:23pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/9 "2019-12-03T16:23:49Z")

</div>

Everytime we solve a problem, another one comes up XD. Now, this line of code is underlined in red:

```auto
surface = super.initSurface();

```

And the error message,  
**Type mismatch, “processing.core.PSurface” does not match with "processing.javafx.PSurfaceFX"**

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [December 4, 2019, 3:36pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/10 "2019-12-04T15:36:53Z")

</div>

We defined the type of the `surface` variable as `PSurfaceFX`.

`PSurfaceFX` is a sub-type of `PSurface`.

`super.initSurface()` does indeed return a `PSurfaceFX` object but the compiler only knows that it is an object of type `PSurface`.

So, we need to **cast** the `PSurface` object that it returns to a `PSurfaceFX` type, so the type corresponds with the `surface` variable:

`surface = (PSurfaceFX) super.initSurface();`

---

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [December 4, 2019, 8:40pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/11 "2019-12-04T20:40:10Z")

</div>

Alright that worked, but now I get a null pointer exception on `stage.setResizable(false);` because the stage has not been initialized yet. I’ve been putting this code right above setup().

```auto
PSurfaceFX surface;
Canvas canvas;
Scene scene;
Stage stage;

@Override
protected PSurface initSurface() {
    surface = (PSurfaceFX) super.initSurface();
    canvas = (Canvas) surface.getNative();
    scene = canvas.getScene();
    stage.setResizable(false);
    return surface;
}

void setup() {
  size(400, 464, FX2D);

```

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [December 4, 2019, 10:43pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/12 "2019-12-04T22:43:38Z")

</div>

haha. my code example was missing it:

`stage = (Stage) scene.getWindow();`

---

<div class="post-metadata">

### Author: ![thesuperdaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thesuperdaine/32/11563_2.png) [@thesuperdaine](https://discourse.processing.org/u/thesuperdaine)
#### Post date: [December 4, 2019, 11:43pm UTC](https://discourse.processing.org/t/fx2d-resizable-window-error/15995/13 "2019-12-04T23:43:56Z")

</div>

Omg it worked! Wow that was a real journey we went on for such a tiny thing XD! Thank you so much for your help.  
Now, I have no idea which one of your messages I should mark as the solution because the solution is spread out over all of your messages xP
