0

I've been working on a little Java project of mine and ofcourse I had to run into issues.

What i'm trying to do

I'm currently trying to use an applet and a glasspane in a JFrame. So I can draw on the glasspane instead of the applet (because I'm loading an external applet).

So my goal is to have a glasspane on top of the applet.

What is happening now?

Well, the glasspane only works when I remove the applet. It simply doesn't draw over the applet. Which is really strange.

Do you guys know what is going on? Your help is greatly appreciated.

public MainUI() {
    try {
        setLayout(new BorderLayout(0, 0));
        Loader loader = new Loader();
        loader.getUrl();
        game = loader.loadGame();
        game.setPreferredSize(new Dimension(765, 503));
        game.setVisible(true);

        getContentPane().add(game);

        JPanel panel = new JPanel() {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            public void paintComponent(Graphics g)  
               {  
                  g.setColor(Color.red);  

                  //Draw an oval in the panel  
                  g.drawString("Hello World!", 10, 10);  
               }  
        };
        setGlassPane(panel);
        panel.setVisible(true);
        panel.setOpaque(false);
        getContentPane().setPreferredSize(new Dimension(765, 503));

        pack();
        revalidate();
        repaint();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Frunk
  • 180
  • 1
  • 2
  • 11
  • 1
    JPanel can't be parent for GlassPane. glass pane is ...., more in Oracle tutorial - Using Top-Level Containers – mKorbel Nov 22 '14 at 15:34
  • The important part of the comment by @mKorbel can be summarized as *"Oracle tutorial - Using Top-Level Containers"*. Plug it into a search engine and go from there. – Andrew Thompson Nov 23 '14 at 01:24

0 Answers0