# Making a program without a window border (and no background, just the shape)

**URL:** <https://discourse.processing.org/t/making-a-program-without-a-window-border-and-no-background-just-the-shape/41260>\
**Category:** Coding Questions\
**Created:** [March 13, 2023, 7:05am UTC](https://discourse.processing.org/t/making-a-program-without-a-window-border-and-no-background-just-the-shape/41260 "2023-03-13T07:05:30Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [October 16, 2023, 7:28am UTC](https://discourse.processing.org/t/making-a-program-without-a-window-border-and-no-background-just-the-shape/41260/18 "2023-10-16T07:28:55Z")

</div>

Hi,

@glv’s example slightly modified…

Cheers  
— mnse

> **Code**
>
> ```auto
> // Display an image without window border and transparent background
> // Author: glv
> // Date: 2023-10-15
> // Insight gleaned from various sources; seek and you shall find.
> 
> // slightly modified @mnse ;)
> 
> import processing.awt.*;
> import java.awt.*;
> import javax.swing.*;
> import java.awt.image.BufferedImage;
> import javax.imageio.ImageIO;
> import java.net.URL;
> 
> import java.awt.event.KeyEvent;
> import java.awt.event.KeyListener;
> import java.awt.event.MouseEvent;
> import java.awt.event.MouseListener;
> import java.awt.event.MouseMotionListener;
> 
> ImageIcon img;
> BufferedImage bimg;
> 
> MouseAndKeyHandler mouseAndKeyHandler; // moving by mouse and exit on ESC key
> 
> void setup() {
> surface.setVisible(false);
> PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surface.getNative();
> JFrame frame = (JFrame) canvas.getFrame();
> frame.dispose();
> String imgPath = dataPath("hand.gif"); // you can use also an animated gif :)
> img = new ImageIcon(imgPath);
> frame = new JFrame();
> frame.setPreferredSize(new Dimension(img.getIconWidth(), img.getIconHeight()));
> frame.add(new JLabel(img));
> mouseAndKeyHandler = new MouseAndKeyHandler(frame);
> frame.addMouseListener(mouseAndKeyHandler);
> frame.addMouseMotionListener(mouseAndKeyHandler);
> frame.addKeyListener(mouseAndKeyHandler);
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> frame.setUndecorated(true);
> frame.setBackground(new Color(0, 0, 0, 0));
> frame.pack();
> frame.setLocationRelativeTo(null);
> frame.setVisible(true);
> }
> 
> class MouseAndKeyHandler implements MouseListener, MouseMotionListener, KeyListener {
> JFrame frame;
> PVector mouse;
> 
> public MouseAndKeyHandler(JFrame f) {
> frame=f;
> mouse = new PVector();
> }
> 
> @Override public void mousePressed(MouseEvent e) {
> mouse.set(e.getX(), e.getY());
> }
> 
> @Override public void mouseReleased(MouseEvent e) {
> mouse.mult(0);
> }
> 
> @Override public void mouseDragged(MouseEvent e) {
> frame.setLocation(floor(frame.getLocation().x + (e.getX() - mouse.x))
> , floor(frame.getLocation().y + (e.getY() - mouse.y)));
> }
> 
> @Override public void mouseMoved(MouseEvent e) {
> }
> 
> @Override public void mouseClicked(MouseEvent e) {
> }
> 
> @Override public void mouseEntered(MouseEvent e) {
> }
> 
> @Override public void mouseExited(MouseEvent e) {
> }
> 
> @Override public void keyPressed(KeyEvent e) {
> }
> @Override public void keyTyped(KeyEvent e) {
> }
> @Override public void keyReleased(KeyEvent e) {
> if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
> frame.dispose();
> }
> }
> }
> 
> ```
> 
> hand.gif (to download, right click and save as): ![hand.gif](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/f/7ffb75287996456ecf2fc2a6faf0f64738434d62.gif)

![16-10-2023_09-22-54](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/e/5e844196528e50a82cd6bdf7e0087d118ce001a9.gif)

---

_[View the full topic](https://discourse.processing.org/t/making-a-program-without-a-window-border-and-no-background-just-the-shape/41260)._
