How to make a program windowless/frameless?

So lets say I have this;

void setup(){
  size(200, 200);
  surface.setAlwaysOnTop(true);
}

void draw(){
  fill(255);
  textSize(35);
  text("Hello",50,75);
}

How can I get rid of the window frame and the background behind hello? Just hello showing up on screen?

I tried surface.setVisible(false); but it didn’t work.

And another question if anyone knows: How can I make the program see keyboard strokes outside the program ( like when the program isn’t clicked) ?

Another edit: found how to remove title bar but still don’t know about others

Another another edit: turns out the frame background doesn’t support transparency… f

1 Like
void setup() {
  fullScreen();
  surface.setSize(200, 200); //Change size here
}

void draw() {
  background(0);
  ellipse(mouseX, mouseY, 20, 20);
}
2 Likes

Yep, I found that after posting. Thanks anyway!

The frame background can have transparency, at least for the JAVA2D / “default” renderer in Processing. Here’s a post the question of which shows code for doing so:

I had myself used this technique many months ago, and it works nicely! I don’t know if the code in the aforementioned post still works as expected, but feel free to ask me for my old code if it doesn’t.

1 Like

Right on,

I was going to suggest fullScreen(SPAN); for apps that use the entire screen.

I’d love to get a sample of your code that has transparent window/background.

I literally just posted that question in the Code subforum

Thank you in advance!

Hello there…
…Iiiiiiiii know it has been 6 months, but it’s important that I write the answer here even though I’m this terribly late. At least for future readers.

Steps on how I did that back then:

  • Use the JAVA2D renderer in your call to size(),
  • Now we write some Java AWT code!
  • Get the AWT JFrame from your Processing sketch by using PApplet::getSurface(), then calling PSurface::getNative() on it, and casting it to a JFrame.
  • Give it a transparent background using JFrame::setBackground(). Pass a new Color(0, 0, 0, 1) into it. I think this has to be repeated in PApplet::draw().
  • Call JFrame::setOpacity() with 0.5f or a similar value. Setting the alpha in the background-color to 1 in the [1, 255] range that AWT accepts is enough only on Windows; opacity control is required everywhere else. It’s just neater to use it anyway…!
  • Use as desired!

The code is here: [ AndroidGameControllerLegacy/src/com/brahvim/androidgamecontroller/server/Sketch.java at 88b1cd89d853cf5d2304f013be57523a9fec0c3b · Brahvim/AndroidGameControllerLegacy · GitHub ], …though I realize now that it skipped over the entire concept of JFrame::setOpacity()!

I also realized that I essentially re-created Processing’s event-handling using AWT listeners, but in a poorer manner - one that does not consider using PApplet::handle*Event() methods. That part is apparently entirely useless!

Anyway. Here’s a minimal example:

import processing.awt.PSurfaceAWT;
import javax.swing.JFrame;

JFrame g_frame;

void setup() {
  g_frame = (JFrame) ((PSurfaceAWT.SmoothCanvas) super.getSurface().getNative()).getFrame();

  g_frame.removeNotify();

  g_frame.setUndecorated(true);

  g_frame.setBackground(new java.awt.Color(0, 0, 0, 1));
  g_frame.setOpacity(0.5f);

  g_frame.addNotify();

  rectMode(CENTER);
}

void draw() {
  background(0, 127);
  square(width * 0.5f, height * 0.5f, sin(millis() * 0.001f) * 40);
}

While digging through my archives, I also discovered a way to make “undecorated” windows in P3D mode.

import com.jogamp.newt.opengl.GLWindow;

GLWindow g_window;

void settings() {
  size(400, 400, P3D);
}

void setup() {
  g_window = (GLWindow)surface.getNative();
  super.surface.initOffscreen(this);
  registerMethod("post", this);
  textMode(MODEL);
}

void draw() {
  background(0, 102, 153, 1);

  noStroke();
  rect(0, 0, width, 30);

  stroke(0);
  fill(0);
  text("Press escape to close, :D", 10, 20);

  fill(255);
  circle(200, 200, abs(sin(millis() * 0.001f) * 50));
}

void post() {
  if (frameCount == 1 && !g_window.isUndecorated()) {

    try {
      
      g_window.setVisible(false);
      g_window.setUndecorated(true);
      while (!g_window.isUndecorated());
      g_window.setVisible(true);
      
    }
    catch(Exception e) {
      
    }

  }
}

Bonus: If you’d like to turn a P3D sketch into a “fullscreen”-ed one dynamically - that is, while it’s running - check out this trick you can perform in PApplet::post() that I used in my years-old project: [ TheNerdProject/src/com/brahvim/nerd/window_management/window_module_impls/NerdGlWindowModule.java at 003b1654ffdac4aee77af0d0c9fe23030ce4cfb6 · Brahvim/TheNerdProject · GitHub ].

All we’re doing here is literally “[busy-]waiting” until the GLWindow is fullscreen. Tracking time.
…Like every other time, here’s a simpler Processing sketch that should get you started [and done!]:

import com.jogamp.newt.opengl.GLWindow;

boolean fullscreen, pfullscreen;
GLWindow g_window;

void settings() {
  size(640, 480, P3D);
  super.registerMethod("post", this);
}

void setup() {
  g_window = (GLWindow) super.getSurface().getNative();
}

void draw() {
  background(0);
}

void keyPressed() {
  if (keyCode == 70) { // The `F` key. Think "Fullscreen"!

    fullscreen = !fullscreen;
    println("Changing screens...");

  }
}

void post() {
  if (pfullscreen != fullscreen) {

    g_window.setFullscreen(fullscreen);

    final long fsStartMillis = System.currentTimeMillis();

    while (fullscreen != g_window.isFullscreen()) {
      
      if (System.currentTimeMillis() - fsStartMillis > 5000) {
       
        break; // Throw an exception instead?
    
      }
  
    }

  }

  pfullscreen = fullscreen;
}