Search code examples
javaswingjwindow

How to apply for JWindow setAlwaysOnTop in Java? Where other JWindows are already also applied to setAlwaysOnTop


I have 3 layered window (like Gimp software). All my JWindow is assigned to setAlwaysOnTop for some display reasons with (xrandr --output VGA --left-of LVDS).

But I need one out of those three to be "the super main always on top, whatever it moves or get drags it always stay as super on top". How can I set that one?

Toolbox.java << he should be the very very super on top always for any drag or etc

public class Toolbox extends JWindow
{
  public Toolbox() {
    ..
    this.setVisible(true);
    this.setAlwaysOnTop(true);
  }
}

Layers.java < normal as it is

public class Layers extends JWindow
{
  public Layers() {
    ...
    this.setVisible(true);
    this.setAlwaysOnTop(true);
  }
}

Drawing.java < normal as it is

public class Drawing extends JWindow
{
  public Drawing() {
    ...
    this.setVisible(true);
    this.setAlwaysOnTop(true);
  }
}

$ java -jar MyGimp.jar
- first it launch Drawing
- secondly it launch Layers
- Thirdly at the end it launch Toolbox
- But in Display I see only Drawing and Layers sometimes, but I never see Toolbox

When I launch the Drawing window then all my toolbox and layers window gets behind. But I want Toolbox window forever stay on top unless I close it. How to do that?


Solution

  • The last component that is set to be on top overrides any previous components. What you do is just reset the Toolbox to be on top after you create Drawing.