Hello folks!
This is an exploration of native window access in P2D/P3D and JAVA2D.
In my Windows 10 environment, I was seeing offsets, and I was compelled to understand why.
And now I do!
P2D Code
// Author: GLV
// Date: 2026-04-014
// Description:
// This is an exploration of native window access in P2D/P3D,
// where the underlying GLWindow lets us read the window insets.
// This is displayed in console:
// The sketch has been resized from 1920x1200 to 1920x1181 by the operating system.
// This happened outside Processing, and may be a limitation of the OS or window manager.
import com.jogamp.newt.opengl.GLWindow;
void settings()
{
int w = displayWidth;
int h = displayHeight;
size(w, h, P2D); // or P3D
}
void setup()
{
GLWindow glw = (GLWindow) surface.getNative();
int left = glw.getInsets().getLeftWidth();
int right = glw.getInsets().getRightWidth();
int top = glw.getInsets().getTopHeight();
int bottom = glw.getInsets().getBottomHeight();
println("Insets L/T/R/B = " + left + " / " + top + " / " + right + " / " + bottom);
// Give these a try:
//surface.setVisible(true); // Show (true) or hide (false) the window
//surface.setLocation(0, 0); // Set desired window position (0, 0); frame insets will shift the sketch area.
//surface.setLocation(-in.left, 0); // Offsets the left frame border so the sketch area starts at the desired position.
//surface.setResizable(true); // Lets the window be resized or maximized
}
void draw()
{
fill(random(64, 128+64));
circle(random(width), random(height), 20);
}
JAVA2D Code
// Author: GLV
// Date: 2026-04-014
// Description:
// This is an exploration of native window access in JAVA2D,
// where the underlying AWT Frame lets us read the window insets.
import processing.awt.PSurfaceAWT;
import java.awt.Insets;
void settings()
{
int w = displayWidth;
int h = displayHeight;
println(w, h);
size(w, h, JAVA2D);
}
void setup()
{
PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surface.getNative();
Insets in = canvas.getFrame().getInsets();
println("Insets L/T/R/B = " + in.left + " / " + in.top + " / " + in.right + " / " + in.bottom);
// Give these a try:
//surface.setVisible(true); // Show (true) or hide (false) the window
//surface.setLocation(0, 0); // Set desired window position (0, 0); frame insets will shift the sketch area.
//surface.setLocation(-in.left, 0); // Offsets the left frame border so the sketch area starts at the desired position.
//surface.setResizable(true); // Lets the window be resized or maximized
}
void draw()
{
fill(random(64, 128+64));
circle(random(width), random(height), 20);
}
That was fun!
:)