Skip to content
Advertisement

bring JInternalFrame to the front

I have a JDesktopPane which contains a number of JInternalFrames. I’d like to be able to bring any JInternalFrame to the front, overlaying any other active frames. I found a number of code samples to do this, but none seem to work – the frame does NOT go on top of other active JInternalFrames. E.g.

public static void moveToFront(final JInternalFrame fr) {
        if (fr != null) {
            processOnSwingEventThread(new Runnable() {
                public void run() {
                    fr.moveToFront();
                    fr.setVisible(true);
                    try {
                        fr.setSelected(true);
                        if (fr.isIcon()) {
                            fr.setIcon(false);
                        }
                        fr.setSelected(true);
                    } catch (PropertyVetoException ex) {
                        ex.printStackTrace();
                    }
                    fr.requestFocus();
                    fr.toFront();
                }
            });
        }
    }

Advertisement

Answer

According to the API toFront or moveToFront should work (though toFront looks to be the better of the two from my reading of the API). Are these JInternalFrames sitting in a JDesktopPane? According to your post it seems they are. I wonder if the error lies elsewhere.

Consider creating and posting an SSCCE (please click on the link), a small compilable, runnable program that demonstrates your best attempt at solving this. Then we can inspect your code, run it, modify it and best be able to help you fix it.

Here is my example of an SSCCE:

JavaScript
Advertisement