Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing Windows "always on top" in WPF app

Tags:

java

c#

wpf

swing

for some reasons, we have an application built with WPF 4, but in some cases we have to show a windows built using java swing. The problem is, you can set some Window as parent of some dialog or other windows, but always in the same technology.

But when we launch another window that is not built using WPF is very easy to that window to be hidden behind WPF app, and is not easy way to put in front WPF.

Is there any way to put that Java windows "on top" of WPF app?

like image 306
Jesús Galindo Avatar asked Mar 22 '23 00:03

Jesús Galindo


1 Answers

Window#toFront() and Window#setAlwaysOnTop() can help.

If you need to set window always on top, use setAlwaysOnTop() method.

If you want window to get focus, toFront() or setAutoRequestFocus() may help.

Try this:

import javax.swing.JFrame;

public class NewClass1 {
    public static void main(String[] args) {
        JFrame frame = new JFrame("On Top");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(100, 100);
        frame.setVisible(true);
        frame.toFront();
    }
}
like image 150
nullptr Avatar answered Mar 31 '23 20:03

nullptr