Skip to content
Advertisement

GlassPane is not showing up on JFrame

I have been trying to implement a GlassPane for my games’ in-game HUD, but right now I cant seem to get the JFrame to set my GlassPane as its own i;ve used setGlassPane() and Ive been reading up a few examples trying to find my mistake, but nothing. So I wrote a SSCCE that demonstrates my problem. I have a JFrame to which I add a Jpanel with a label “TESTIING” then I initiate my galss pane and call setGlassPane() on my frames instance. My GlassPane has a MouseListener, a JPanel and 2 JLabels, and an overriden paint() however the MouseListener wont work the paint() wont show and my labels are not there (so basically my GlassPane is not being set as my frames new GlassPane)-

JavaScript

Thanks you.

Advertisement

Answer

It seems that you have to first add the custom GlassPane as your frames GlassPane before making the GlassPane visible! This code here seemed to work:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement