JMenu doesn't go away when try to click off

Posted on 2004-09-16
Last Modified: 2010-03-31
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:  You'll also need the .jpg which is here:  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!
Question by:thearchitect2
  • 4
  • 3
LVL 92

Expert Comment

ID: 12081106
instead of overriding paint() you should override paintComponent()

Author Comment

ID: 12081126
I had that in the first place, but then I switched them hoping paint() would work better.  What's the difference between the two?
LVL 92

Expert Comment

ID: 12081152
paint() is responsible for painting the component, it's children, it's border etc.
paintComponent() is just for painting that actual component.
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 12081166
Ok, that's always good to know. I tried changing it back, but it still leaves the menu there and it doesn't disappear.
LVL 92

Accepted Solution

objects earned 250 total points
ID: 12081168
try this:

    public void paintComponent(Graphics g) {
        final int newX = getIntX()/5;
        final int newY = getIntY()/12;
        final int width = newX*3;
        final int height = newY*4;
    }    //close paint()

Author Comment

ID: 12081193
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.
LVL 92

Expert Comment

ID: 12081213
you need to ensure you paint all of the panels background.

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 80
JDeveloper 12c for 32 bit 4 84
servlet example 17 29
Java: How do I open the default windows program for a given file type 3 28
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question