Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7430385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:07:54+00:00 2026-05-29T09:07:54+00:00

I have a class PanelFormes that extends JPanel, which I use as a container.

  • 0

I have a class PanelFormes that extends JPanel, which I use as a container. I also have two other JPanel, one to paint some figure in it, the second one contains buttons. These two JPanel are included into the first one, using BorderLayout.

One my buttons is supposed to call the repaint method of the JPanel where there should be figures. In my main window constructor, I do that:

boutonGetForme.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

        ajoutForme(rect);
    }
});

The method ajoutForme, in my main window class :

// Methode ajout de forme, normalement appelee par le controleur
public void ajoutForme(Forme f) {

    //dire au jpanel quelle forme on veut dessiner et comment
    jpanel.definirForme(f);
    //mettre a jour le jpanel
    jpanel.repaint();  
}

And finally the class PanelFormes :

package gui;

import java.awt.Graphics;
import javax.swing.JPanel;

public class PanelFormes extends JPanel {

private Forme f;
PanelFormes() {
    f = new Rectangle(1,1,1,1);
}
public void definirForme(Forme f) {
    this.f = f;
}
public void paintComponent(Graphics g) {
    //dessiner la forme
    f.dessine(g);
}            
}

I think I gave you all relevants informations.
My problem is that, when I try to paint a figure with the button buttonGetForme, I not only get the figure, but also some weird screenshot-copy of the very button I just pressed, that is pasted in the upper left corner of my JPanel, I really wonder how…
If I try to paint the figure by calling ajoutForme directly, it works just fine. There must be something with the ActionListener, but I can’t understand what…
I am a newbee in Java, any help will be very much appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:07:55+00:00Added an answer on May 29, 2026 at 9:07 am

    If you setOpaque(true), verify that you are completely rendering the area defined by the component’s bounds; if not, use setOpaque(false). If the problem persists, please edit your question to include an sscce that exhibits the artifact.

    Addendum: See also Painting in AWT and Swing: Opacity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class A that has some primitive attributes and also member of type
I have class class DateOptTimeType implements org.hibernate.usertype.UserType that works with two columns @org.hibernate.annotations.Type(type =
I have class which has a method that needs to return three DataTables. I
I have class that extends BroadcastReceiver and gets all new sms. When I get
I have class method that returns a list of employees that I can iterate
I have: class MyClass extends MyClass2 implements Serializable { //... } In MyClass2 is
I have class with a member function that takes a default argument. struct Class
I have: class Car {..} class Other{ List<T> GetAll(){..} } I want to do:
I have class A, which exposes an event. an object of class B subscribed
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.