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 7771971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:46:38+00:00 2026-06-01T16:46:38+00:00

Without using super.paintComponent(g); can i still clear my Jpanel or Jframe Screen? I have

  • 0

Without using super.paintComponent(g); can i still clear my Jpanel or Jframe Screen? I have some shapes drawn on JPanel and i want to clear all the drawing when user presses the right click without Using this method. or i say is there any alternate of super.paintCompenent(g);method or method like clrscr(); In Java.

EDIT

  public void mousePressed(MouseEvent e) {
            super.paintComponents(null); //i want to use this method here?? how can i? 
            if(e.isPopupTrigger())
            {
                s=e.getX();
                as=e.getY();
              try {
                    Thread.sleep(10L);
                } catch (InterruptedException ex) {
                    Logger.getLogger(animate.class.getName()).log(Level.SEVERE, null, ex);
                }
        p.repaint();
            }
        }

i am painting the shape like this

public class mypanel extends JPanel {

   @Override
    public void paintComponent(Graphics g)
    {

       super.paintComponent(g);
        Graphics2D g2=(Graphics2D)g ;

        Color[] c = {Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW, 
                 Color.MAGENTA, Color.WHITE, Color.ORANGE, Color.PINK};
    for(int i=0; i<8; ++i){
        g2.setColor(c[i]);
        int start_angle=i*45;
    g2.fillArc(mx-100, my-100, 200, 200, start_angle,45);



    }
  • 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-06-01T16:46:40+00:00Added an answer on June 1, 2026 at 4:46 pm

    mre solution is actually a good idea, but you may have issues if another repaint comes in (because you move the JFrame, because you resize it, because another window comes on top of it and then leavs, etc…)

    Alternatively, you can have something like this to make the change permanent:

    public class mypanel extends JPanel {
    
        private boolean draw = true;
    
        @Override
        public void paintComponent(Graphics g)
        {
    
            super.paintComponent(g);
            if (draw) {
                Graphics2D g2=(Graphics2D)g ;
    
                Color[] c = {Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW, 
                         Color.MAGENTA, Color.WHITE, Color.ORANGE, Color.PINK};
                for(int i=0; i<8; ++i){
                    g2.setColor(c[i]);
                int start_angle=i*45;
                g2.fillArc(mx-100, my-100, 200, 200, start_angle,45);
            }
        }
    
        public void setDraw(boolean draw) {
            this.draw = draw;
            repaint();
        }
    }
    

    And then you can just draw or not in your JPanel simlpy by calling mypanel.setDraw(boolean)

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

Sidebar

Related Questions

How to inject method (using reflection) into super class without extending tested class? I
Without using the Graphic Resources how can I create and build up a CTabCtrl?
Is it possible without using exponentiation to have a set of numbers that when
I want to create a custom View which contains two buttons without using xml.
I have recently come across a very simple Typed DataTable (without using a .XSD)(I've
I want to call a method of super class of a super class, without
I'm a beginner. I just want to draw a simple line without using IB
Without using jQuery, what is the best way to limit text entry of a
without using a database i wanted a file to point to the newest revision
Without using percentages, is it possible to position a background image 2px from the

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.