transparent JWindow stuck in front of everything and can't be disposed

90 Views Asked by At

I'm coding an app that controls an educational competition and displays the questions and the media on the extended screen, every while i need to display the scores, so on a button click, a new JFrame is created and plays a video using VLCJ, and on an other button click, that JFrame should be disposed to continue the competition.. after some googling and asking a question here, i came up with this code to be able to display JLabels on top of a video:

mediaPlayerComponent = new EmbeddedMediaPlayerComponent() {

            private static final long serialVersionUID = 1882423084923822679L;

                @Override
                protected Window onGetOverlay() {

                    final JWindow transparentWindow = new JWindow();

                    transparentWindow.setOpacity(1.0f);
                    transparentWindow.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.0f));
                    transparentWindow.getContentPane().setLayout(null);

                    int x = height/7;
                    for (int i = 0 ; i < numberOfTeams ; i++) {

                        scores[i][0] = new JLabel(scoresArray[i][0]);
                        scores[i][0].setOpaque(false);
                        scores[i][0].setBounds(width/2+width/80, x, width/5, height/16);


                        scores[i][1] = new JLabel(scoresArray[i][1]);
                        scores[i][1].setOpaque(false);
                        scores[i][1].setHorizontalAlignment(SwingConstants.RIGHT);
                        scores[i][1].setBounds(width/2-width/5-width/80 , x, width/5, height/16);

                        transparentWindow.getContentPane().add(scores[i][0]);
                        transparentWindow.getContentPane().add(scores[i][1]);

                        x = x + height/16;
                    }
                    return transparentWindow;
            }
};

it works amazingly great the 1st time i display the scores, after disposing the scores JFrame using mediaplayer.stop() and scoresFrame.dispose(), the JWindow with its labels still appears on top of the questions. and if i wanted to redisplay the scores, the JWindow doesn't show at all on top of the video.

Some pictures of the problem:

the scores are being displayed: the scores are being displayed successfully

after disposing the scoresFrame and returning to the main frame (where questions are being displayed) JWindow is not being disposed

So what am i missing here??

any help is appreciated. thanks in advance.

0

There are 0 best solutions below