# Get location of a PApplet window

**URL:** https://discourse.processing.org/t/get-location-of-a-papplet-window/28039
**Category:** Coding Questions
**Created:** [February 24, 2021, 6:45am UTC](https://discourse.processing.org/t/get-location-of-a-papplet-window/28039 "2021-02-24T06:45:20Z")
**Posts on this page:** 1
**Showing post:** 10

<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: [February 25, 2021, 2:25pm UTC](https://discourse.processing.org/t/get-location-of-a-papplet-window/28039/10 "2021-02-25T14:25:25Z")

</div>

> <https://stackoverflow.com/questions/65600999/need-a-java-processing-class-for-moving-mouse-to-window-center/65603498#65603498>

```auto
PVector getWindowLocation() {

  PVector windowLocation = new PVector();

  switch (sketchRenderer()) {
  case P2D:
  case P3D:
    com.jogamp.nativewindow.util.Point p = new com.jogamp.nativewindow.util.Point();
    ((com.jogamp.newt.opengl.GLWindow) surface.getNative()).getLocationOnScreen(p);
    windowLocation.x = p.getX();
    windowLocation.y = p.getY();
    break;
  case FX2D:
    final processing.javafx.PSurfaceFX FXSurface = (processing.javafx.PSurfaceFX) surface;
    final javafx.scene.canvas.Canvas canvas = (javafx.scene.canvas.Canvas) FXSurface.getNative();
    final javafx.stage.Stage stage = (javafx.stage.Stage) canvas.getScene().getWindow();
    windowLocation.x = (float) stage.getX();
    windowLocation.y = (float) stage.getY();
    break;
  case JAVA2D:
    java.awt.Frame f = (java.awt.Frame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative())
        .getFrame();
    windowLocation.x = f.getX();
    windowLocation.y = f.getY();
    break;
  }

  return windowLocation;
}

```

---

_[View the full topic](https://discourse.processing.org/t/get-location-of-a-papplet-window/28039)._
