1

I want an InternalFrame to be shown in front of a GlassPane. In my program the user should be able to click on FILE -> Settings and an InternalFrame should be displayed. Everything in the background should be covered with a GlassPane. Does somebody have an idea?

m21.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        Settings settings = new Settings();

        //get the InternalFrame
        settings.getFrame().setBounds(100,100,getWidth()-200, getHeight()-200);
        settings.getFrame().toFront();

        setGlassPane(new Glass());
        getGlassPane().setVisible(true);

        //get the InternalFrame
        getLayeredPane().add(settings.getFrame(), BorderLayout.NORTH);
        getLayeredPane().moveToFront(settings.getFrame());

        repaint();
    }
});

GlassPane

Abra
  • 19,142
  • 7
  • 29
  • 41
  • 1
    Reading [How to use Rootpanes](https://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html) this does not seem possible. A `GlassPane` is added on top of all other components including a `JLayeredPane`. Perhaps a `JDialog` would work – David Kroukamp Dec 21 '20 at 07:44
  • 2
    Seems like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). I assume that your class `Glass` extends `JPanel`. You can add `JComponent`s to it just like you can for any `JPanel`. Why does it have to be a `JInternalFrame`? I think a modal `JDialog` is also a possibility. Maybe even a `JOptionPane`. Or even a [modal internal frame](https://stackoverflow.com/questions/11177003/making-a-modal-jinternalframe). – Abra Dec 21 '20 at 08:22

1 Answers1

0

The point of the glass pane is to be in front of everything else:

glasspane

However, you can set any component as glass pane. My suggestion would be that you push the content of your settings frame as glass pane.

Reto Höhener
  • 5,419
  • 4
  • 39
  • 79