Making an Unfocusable Window in Java

awt, java, jframe, swing, user-interface

Solution

You want to use `setFocusableWindowState(false)`

(fwiw, this was in the API document linked by the top answer of the post you referred to)

edit: what about adding a listener to window state change that executes `toBack()`?

edit: you might also consider overriding the `toFront` method to prevent anything from pulling the window to the front.

Problem

(SOLVED: a `WindowStateListener` and a deferred call to `toBack` whenever the window is focused) Hello all! I've been trying to figure out how to make a `java.awt.Window` (any subclass will do) so that it cannot be brought to the front. I'm working on a Java "Samurize-like" program that appears below all the application windows and displays Widgets on the screen. Just like "Always on top windows with Java", I'm hoping for something simple, hopefully just a single method call, if possible, but I've checked through the API docs and I've had no luck. Edit: Sorry, I meant "always on bottom" rather than simply "unfocusable". Here's a basic test case. When clicking on the Window, it should not come above any others currently on the screen: ``` import java.awt.*; import javax.swing.*; public class Main extends JFrame { public Main() { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); setFocusable(false); setFocusableWindowState(false); setBounds(new Rectangle(dim)); toBack(); } public static void main(String[] args) { new Main().setVisible(true); } } ```

Original source

Related problems