# How to make an overlay that overlays over other program

**URL:** https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784
**Category:** Coding Questions
**Created:** [September 15, 2022, 5:33pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784 "2022-09-15T17:33:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![5x9x7x2x7x9](https://avatars.discourse-cdn.com/v4/letter/5/9de0a6/32.png) [@5x9x7x2x7x9](https://discourse.processing.org/u/5x9x7x2x7x9)
#### Post date: [September 15, 2022, 5:33pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/1 "2022-09-15T17:33:07Z")

</div>

Hello, I was wondering if there was any way to make it so I could have a program, that if you switch to another program, it would still be on your screen and you could interact with the other program normally?  
For example, a line that points from the middle of your screen to your mouse cursor.  
Or maybe even effects

---

<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: [September 15, 2022, 5:37pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/2 "2022-09-15T17:37:14Z")

</div>

Do you mean that you want to detect if your sketch is the “active” window?

---

<div class="post-metadata">

### Author: ![5x9x7x2x7x9](https://avatars.discourse-cdn.com/v4/letter/5/9de0a6/32.png) [@5x9x7x2x7x9](https://discourse.processing.org/u/5x9x7x2x7x9)
#### Post date: [September 15, 2022, 5:44pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/3 "2022-09-15T17:44:39Z")

</div>

No I want it to go ontop of other programs without affecting the programs in any way, for example if you clicked on the program it wouldnt switch between them

---

<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: [September 15, 2022, 5:47pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/4 "2022-09-15T17:47:05Z")

</div>

So you mean that the program only puts a graphic on the screen and doesn’t interfere with any of inputs “meant” for another program?

---

<div class="post-metadata">

### Author: ![5x9x7x2x7x9](https://avatars.discourse-cdn.com/v4/letter/5/9de0a6/32.png) [@5x9x7x2x7x9](https://discourse.processing.org/u/5x9x7x2x7x9)
#### Post date: [September 15, 2022, 5:48pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/5 "2022-09-15T17:48:05Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/3/e3fa17a40ee14fedd7817799cee45a531e674469.jpeg)  
For example, Im playing a game, and I have a white line pointing from the middle of my screen to my mouse

---

<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: [September 15, 2022, 5:49pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/6 "2022-09-15T17:49:36Z")

</div>

I understand… There maybe is some trickery to be done with plain Java but processing graphics aren’t intended for that purpose.

---

<div class="post-metadata">

### Author: ![5x9x7x2x7x9](https://avatars.discourse-cdn.com/v4/letter/5/9de0a6/32.png) [@5x9x7x2x7x9](https://discourse.processing.org/u/5x9x7x2x7x9)
#### Post date: [September 15, 2022, 5:54pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/7 "2022-09-15T17:54:05Z")

</div>

Okay, I’m sorry for wasting your time.

---

<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: [September 15, 2022, 6:26pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/8 "2022-09-15T18:26:28Z")

</div>

I just did some research on that and you can create overlays using Java (and therefore processing) take a look at this code:

```auto
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
JFrame drawingFrame=new JFrame("CustomWindow");
drawingFrame.setUndecorated(true);
drawingFrame.setBackground(new Color(0,0,0,0));
drawingFrame.setSize(640,640);
drawingFrame.getContentPane().setLayout(new BorderLayout());
drawingFrame.getContentPane().add(new JTextField(10),"North");
drawingFrame.setAlwaysOnTop(true);
drawingFrame.setVisible(true);
drawingFrame.getRootPane().putClientProperty("apply.awt.draggableWindowBackground",false);
drawingFrame.pack();

```

I could try if I can manage to force the normal processing window in such a state.

---

<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: [September 15, 2022, 7:03pm UTC](https://discourse.processing.org/t/how-to-make-an-overlay-that-overlays-over-other-program/38784/9 "2022-09-15T19:03:43Z")

</div>

@5x9x7x2x7x9  
Here is the program you described! I hope thats what you need!

```auto
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Canvas canv=new ResultOutput();
JFrame drawingFrame=new JFrame("CustomWindow");
void setup() {
  size(50, 50);
  //creates an empty window
  drawingFrame.setUndecorated(true);
  drawingFrame.setBackground(new Color(0, 0, 0, 0));
  drawingFrame.add(canv);
  canv.setBackground(new Color(0, 0, 0, 0));
  drawingFrame.setSize(displayWidth, displayHeight);
  drawingFrame.setAlwaysOnTop(true);
  
  drawingFrame.setVisible(true);
  drawingFrame.getRootPane().putClientProperty("apply.awt.draggableWindowBackground", false);
  drawingFrame.pack();
  //hides the Processing window
  getSurface().setVisible(false);
}
Point p=MouseInfo.getPointerInfo().getLocation();
void draw() {
  //get the mousePosition
  p=MouseInfo.getPointerInfo().getLocation();
  canv.revalidate();
  //refresh the canvas
  SwingUtilities.updateComponentTreeUI(drawingFrame);
}
void mousePressed() {
}
public class ResultOutput extends Canvas {
  public void paint(Graphics g) {
    int strokeWidth=5;
    Graphics2D g2=(Graphics2D) g;
    //here you can paint the screen
    g2.setColor(Color.BLACK);
    g2.setStroke(new BasicStroke(strokeWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    g2.drawLine(displayWidth/2,displayHeight/2,p.x,p.y);
    //g2.drawOval(p.x,p.y,strokeWidth/2,strokeWidth/2);
    
    //This allows you to always click
    g2.clearRect(p.x,p.y,1,1);
  }
}

```

Edit: added a way to set a custom strokeWeight
