Solved

JMenu doesn't go away when try to click off

Posted on 2004-09-16
7
175 Views
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: 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!
0
Comment
Question by:thearchitect2
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

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

Author Comment

by:thearchitect2
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 12081152
paint() is responsible for painting the component, it's children, it's border etc.
paintComponent() is just for painting that actual component.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:thearchitect2
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.
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 12081168
try this:

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        final int newX = getIntX()/5;
        final int newY = getIntY()/12;
        final int width = newX*3;
        final int height = newY*4;
        g.drawImage(logo,newX,newY,width,height,this);
    }    //close paint()
0
 

Author Comment

by:thearchitect2
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.
0
 
LVL 92

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modeling a class in java 5 47
how do i compare an object based on two fields 6 49
jar file executable 12 40
ForLoop Example 3 40
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now