# getLocation() of the sketch

**URL:** <https://discourse.processing.org/t/getlocation-of-the-sketch/5763>\
**Category:** Coding Questions\
**Created:** [November 20, 2018, 2:29pm UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763 "2018-11-20T14:29:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [November 20, 2018, 2:29pm UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763/1 "2018-11-20T14:29:47Z")

</div>

I try to catch the location of my sketch, but I don’t find any option to do that like `surface.setLocation()`. Any idea which method can be used to catch the sketch position, like before `getLocationOnScreen()`

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [November 20, 2018, 7:57pm UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763/2 "2018-11-20T19:57:30Z")

</div>

The `PSurface` class doesn’t expose the location. You’ll have to go through the native window object. This is going to depend on which renderer you’re use.

I’d start here:

[https://processing.github.io/processing-javadocs/core/processing/core/PSurface.html](https://processing.github.io/processing-javadocs/core/processing/core/PSurface.html)

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [November 21, 2018, 8:58am UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763/3 "2018-11-21T08:58:18Z")

</div>

I want something universel, work with P2D, P3D, JAVAFAX, JAVA2D… but I don’t find anything to catch the window object ☹

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 21, 2018, 9:10am UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763/4 "2018-11-21T09:10:58Z")

</div>

- [Forum.Processing.org/two/discussions/tagged?Tag=getnative()](http://Forum.Processing.org/two/discussions/tagged?Tag=getnative%28%29)

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [November 21, 2018, 9:28am UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763/5 "2018-11-21T09:28:52Z")

</div>

Perfect, thx that’s work like a charm !

```auto
int get_sketch_location_x() {
  return getJFrame(getSurface()).getX();
}

int get_sketch_location_y() {
  return getJFrame(getSurface()).getY();
}

 
static final javax.swing.JFrame getJFrame(final PSurface surface) {
  return (javax.swing.JFrame) ( (processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
}

```

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [November 21, 2018, 5:30pm UTC](https://discourse.processing.org/t/getlocation-of-the-sketch/5763/6 "2018-11-21T17:30:00Z")

</div>

improve the detection for the case the sketch is in P2D or P3D

```auto
int get_sketch_location_x() {
  if(get_renderer() != P3D && get_renderer() != P2D) {
    return getJFrame(getSurface()).getX();
  } else {
    return get_rectangle(surface).getX();

  }
  
}

int get_sketch_location_y() {
  if(get_renderer() != P3D && get_renderer() != P2D) {
    return getJFrame(getSurface()).getY();
  } else {
    return get_rectangle(surface).getY();
  }
}

com.jogamp.nativewindow.util.Rectangle get_rectangle(PSurface surface) {
  com.jogamp.newt.opengl.GLWindow window = (com.jogamp.newt.opengl.GLWindow) surface.getNative();
  com.jogamp.nativewindow.util.Rectangle rectangle = window.getBounds();
  return rectangle;
}

static final javax.swing.JFrame getJFrame(final PSurface surface) {
  return (javax.swing.JFrame)
  (
    (processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()
  ).getFrame();
}

```
