I used Java and Swing.
I have two windows MainWindow and PointWindow.
MainWindow is a JFrame window.
PointWindow extends JWindow.
I want to keep PointWindow always on top (never under other windows or components). I set in constructor of PointWindow a setAlwaysOnTop(true) but problem is when I click to to MainWindow (focus), next on different way for example click on my desktop (empty space) and try to drag PointWindow then it is under my MainWindow.
There is any way to keep the PointWindow always on top of all components ?
EDIT
In constructor I tried using a WindowListener as below
this.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
toFront();
}
@Override
public void windowLostFocus(WindowEvent e) {
toFront();
}
});
... but it do not work, the events are not catched
SOLUTION
I add a
MouseAdapteras aMouseListenertoPointWindowand whenmousePressedevent is detected then dotoFront()and work fine but there is one side effect, it means that there is a moment when window is hide and show (very fast).