Link to home
Start Free TrialLog in
Avatar of thearchitect2
thearchitect2

asked on

JMenu doesn't go away when try to click off

I'm trying to put a .jpg, a couple menus, and 2 buttons on a JFrame.  I got the .jpg in there nicely and the two buttons on the bottom and I put the menus in.  I click on the menu or use a ALT+Whatever shortcut to open a menu and that works fine, but when I click again to make it go away, a sort of imprint of it stays on the screen, like it got painted there with the .jpg.  If you want to download the source code, it's here: http://www.geocities.com/thearchitect2/Tetrix.java.  You'll also need the .jpg which is here: http://www.geocities.com/thearchitect2/tetrix.jpg.  I think it has something to do with repainting the panel or something, but I don't know how I would do that.  Thanks a lot for the help!
Avatar of Mick Barry
Mick Barry
Flag of Australia image

instead of overriding paint() you should override paintComponent()
Avatar of thearchitect2
thearchitect2

ASKER

I had that in the first place, but then I switched them hoping paint() would work better.  What's the difference between the two?
paint() is responsible for painting the component, it's children, it's border etc.
paintComponent() is just for painting that actual component.
Ok, that's always good to know. I tried changing it back, but it still leaves the menu there and it doesn't disappear.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot! It's exactly what I wanted!  If you have time, could you explain to me how that made it work? I'm kind of a novice at Java.
you need to ensure you paint all of the panels background.