# Code for foreground window

**URL:** <https://discourse.processing.org/t/code-for-foreground-window/37148>\
**Category:** Coding Questions\
**Created:** [May 27, 2022, 7:08pm UTC](https://discourse.processing.org/t/code-for-foreground-window/37148 "2022-05-27T19:08:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [May 27, 2022, 7:08pm UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/1 "2022-05-27T19:08:48Z")

</div>

Hi there is a code to put window in the foreground, like: SetWindowsPos (0)?

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 27, 2022, 7:16pm UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/2 "2022-05-27T19:16:20Z")

</div>

Is this what you are looking for? This put always puts the window on top.

```auto
import javax.swing.*;
import processing.awt.*;
  JFrame window;
void setup() {
  window=(JFrame) ((PSurfaceAWT.SmoothCanvas)this.getSurface().getNative()).getFrame();
  window.setAlwaysOnTop(true);
}
void draw(){}

```

Or are you looking to change the location of the window?

```auto
import javax.swing.*;
import processing.awt.*;
  JFrame window;
void setup() {
  window=(JFrame) ((PSurfaceAWT.SmoothCanvas)this.getSurface().getNative()).getFrame();
  window.setLocation(0,0);
}
void draw(){}

```

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [May 27, 2022, 7:35pm UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/3 "2022-05-27T19:35:38Z")

</div>

Perfect, it works great, thanks you are the best.

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 27, 2022, 7:51pm UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/4 "2022-05-27T19:51:09Z")

</div>

No problem! For manipulating windows looking up the same thing for JFrames might be worth a shot as JFrames allow for very much manipulation like hiding or resizing. Also Processing uses them for it’s window too.

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [May 28, 2022, 4:49am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/5 "2022-05-28T04:49:48Z")

</div>

An easier way to do it without imports and that AWT stuff is simply,

```auto
surface.setAlwaysOnTop(true);

```

same goes for setting the location

```auto
surface.setLocation(0,0);

```

heres a list of the surface options [PSurfaceNone](http://processing.github.io/processing-javadocs/core/processing/core/PSurfaceNone.html)

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [May 28, 2022, 6:48am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/6 "2022-05-28T06:48:13Z")

</div>

Outstanding Mikey83 was what I was looking for, thank you, you are number one

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [May 28, 2022, 7:11am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/7 "2022-05-28T07:11:13Z")

</div>

Glad to help mate, happy coding

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [May 28, 2022, 7:26am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/8 "2022-05-28T07:26:09Z")

</div>

Thanks, sorry if I take advantage, is there also an instruction to minimize on the traybar and opposite?

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [May 28, 2022, 7:47am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/9 "2022-05-28T07:47:34Z")

</div>

Not that i have seen, maybe with JFrame as@NumericPrime suggested for controlling the window.  
Using surface you could use

```auto
surface.setVisible(false);

```

that will hide the window, then use

```auto
surface.setVisible(true);

```

to make it visible again, bout the closest ive come

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [May 28, 2022, 11:22am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/10 "2022-05-28T11:22:34Z")

</div>

Thanks, I had already tried with “surface.setVisible (true);” but it doesn’t work, I will try, as recommended, to use the instructions inserted by @NumericPrime.

P.S. Sorry my english, but i’m italian.

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [May 28, 2022, 11:31am UTC](https://discourse.processing.org/t/code-for-foreground-window/37148/11 "2022-05-28T11:31:24Z")

</div>

Solved with - window.setState(window.NORMAL); -  
Thank you all for your cooperation.
