# Is it possible to not have the generic windows close buttons and make your own close button?

**URL:** <https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013>\
**Category:** Coding Questions\
**Created:** [July 23, 2018, 12:49pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013 "2018-07-23T12:49:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shimo](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Shimo](https://discourse.processing.org/u/Shimo)\
**Post date:** [July 23, 2018, 12:49pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/1 "2018-07-23T12:49:00Z")

</div>

So I’m talking about applications like discord, they don’t have that ugly windows border around their application, the league of legends client also doesn’t have it, Photoshop also has a custom one. So I know it’s possible but is it possible in processing? And if not, in what language would this be possible?

---

<div class="post-metadata">

**Author:** ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)\
**Post date:** [July 23, 2018, 1:28pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/2 "2018-07-23T13:28:24Z")

</div>

I’m not quite sure if that’s what you wanted, but you could do it by removing the frameborder.  
In Processing 2, it was very easy to do so:

```auto
frame.removeNotify();
frame.setUndecorated(true);
frame.addNotify();

```

In Processing 3, the `frame` variable was replaced with the `surface` variable.  
I don’t think that there is a way to remove the border using `surface` (I could be wrong), but you can still access the frame using `processing.awt.PSurfaceAWT`.  
So you could do it like this:

```auto
import processing.awt.PSurfaceAWT;

void setup(){
  size(800, 600);
  
  PSurfaceAWT awtSurface = (PSurfaceAWT)surface;
  PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();
  smoothCanvas.getFrame().removeNotify();
  smoothCanvas.getFrame().setUndecorated(true);// Hide the window border
  smoothCanvas.getFrame().setLocation(100, 100);// Move the window
  smoothCanvas.getFrame().addNotify();
}

void draw(){
  background(200);
  fill(200, 0, 0);
  noStroke();
  rect(width - 50, 0, 50, 25, 5);
}

void mousePressed(){
  if(mouseX > width - 50 && mouseY < 50){
    exit();// If the mouse is touching the red rectangle, close the sketch
  }
}

```

_Note:_ You won’t be able to move the window if you do it like this (the only way is to use `smoothCanvas.getFrame().setLocation(100, 100);`).

---

<div class="post-metadata">

**Author:** ![Shimo](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Shimo](https://discourse.processing.org/u/Shimo)\
**Post date:** [July 23, 2018, 1:32pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/3 "2018-07-23T13:32:10Z")

</div>

Thank you very much, do you also have an idea how to remove the little grey border it now makes on the right and bottom side?

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [July 23, 2018, 4:56pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/4 "2018-07-23T16:56:23Z")

</div>

With the above code you shouldn’t be getting a border at all. But this might depend on your operating system. Are you using a call to `background()` (and not just drawing a `rect()`)? Can we see your code? Can you show us an image of the sketch?

---

<div class="post-metadata">

**Author:** ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)\
**Post date:** [July 23, 2018, 5:12pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/5 "2018-07-23T17:12:29Z")

</div>

The smallest window size you can get in Processing is 128 \* 128, so if you call `size()` and make your window at least **128 \* 128** pixels big, you shouldn’t see any grey border.

---

<div class="post-metadata">

**Author:** ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)\
**Post date:** [July 23, 2018, 6:03pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/6 "2018-07-23T18:03:32Z")

</div>

Added a bit of code, now you can drag it:

```auto
import processing.awt.PSurfaceAWT;
import java.awt.MouseInfo;
import java.awt.Point;

boolean isInFullscreen;
boolean dragging;
int dragX, dragY;
Button hide, full, close;
PSurfaceAWT awtSurface;
PSurfaceAWT.SmoothCanvas smoothCanvas;

void setup(){
  size(800, 600);
  noStroke();
  
  awtSurface = (PSurfaceAWT)surface;
  smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();
  smoothCanvas.getFrame().removeNotify();
  smoothCanvas.getFrame().setUndecorated(true);// Hide the window border
  smoothCanvas.getFrame().setLocation(100, 100);// Move the window
  smoothCanvas.getFrame().addNotify();
  surface.setResizable(true);
  
  // Menu Buttons
  hide = new Button(width - 115, -5, 40, 25, color(100), 5);
  full = new Button(width - 80, -5, 40, 25, color(150), 5);
  close = new Button(width - 45, -5, 50, 25, color(200, 0, 0), 5);
}

void draw(){
  background(200);
  // Draw Menu Bar
  fill(225);
  rect(0, 0, width, 20);
  hide.display();
  full.display();
  close.display();
}

void mousePressed(){
  if(hide.isMouseOver()){
    smoothCanvas.getFrame().toBack();// Hide window
  }
  if(full.isMouseOver()){
    isInFullscreen = !isInFullscreen;
    if(isInFullscreen){
      smoothCanvas.getFrame().setLocation(0, 0);
      smoothCanvas.getFrame().setSize(displayWidth, displayHeight);
    }else{
      smoothCanvas.getFrame().setLocation(100, 100);
      smoothCanvas.getFrame().setSize(800, 600);
    }
  }
  if(close.isMouseOver()){
    exit();// Close window
  }
  // Drag window
  if(mouseY < 20){
    dragging = true;
    dragX = mouseX;
    dragY = mouseY;
  }
}

void mouseDragged(){
  if(dragging){
    // Get mouse position and move the window
    Point mouse = MouseInfo.getPointerInfo().getLocation();
    smoothCanvas.getFrame().setLocation(mouse.x - dragX, mouse.y - dragY);
  }
}

void mouseReleased(){
  dragging = false;
}

// Menu Button Class
class Button{
  int xpos, ypos;
  int sizeX, sizeY;
  color buttonColor;
  int borderRadius;
  
  Button(int x, int y, int sx, int sy, color c, int br){
    xpos = x;
    ypos = y;
    sizeX = sx;
    sizeY = sy;
    buttonColor = c;
    borderRadius = br;
  }
  
  void display(){
    fill(buttonColor);
    rect(xpos, ypos, sizeX, sizeY, borderRadius);
  }
  
  boolean isMouseOver(){
    if(mouseX > xpos && mouseX < xpos + sizeX && mouseY > ypos && mouseY < sizeY){
      return true;
    }
    return false;
  }
}

```

“How to create your own OS with just 104 lines of code” 🙂

---

<div class="post-metadata">

**Author:** ![Arnau](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/arnau/32/9376_2.png) [@Arnau](https://discourse.processing.org/u/Arnau)\
**Post date:** [June 12, 2020, 8:06pm UTC](https://discourse.processing.org/t/is-it-possible-to-not-have-the-generic-windows-close-buttons-and-make-your-own-close-button/2013/7 "2020-06-12T20:06:00Z")

</div>

You can also define in as fullScreen(); on setup and then do “surface.setSize(400, 400);” and “surface.setLocation((displayWidth/2)-(width/2), (displayHeight/2)-(height/2));”

The code:

```auto
void setup(){
  fullScreen();
  surface.setSize(400, 400);
  surface.setLocation((displayWidth/2)-(width/2), (displayHeight/2)-(height/2));
}

```

(Then you create your own close button)
