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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:30:47+00:00 2026-05-30T21:30:47+00:00

As you see these picture, the background grid lines and black rectangle are not

  • 0

enter image description here

enter image description here

As you see these picture, the background grid lines and black rectangle are not updated after the menu item is closed. How can I update it? In C# there is an event handler to make it updated automatically, but I am newbie to Java swing GUI application.

Here is the code:

public void paint(Graphics g) {

  super.paintComponents(g); 

  MainDisplayForm mD = new MainDisplayForm();           


  Graphics2D g2 = (Graphics2D) g;  

  g2.setColor(Color.BLACK);
  int gridWidth = 1240;
  int gridHeight = 400;      
  g2.fillRect(20, 50, gridWidth, gridHeight);


  g2.setColor(Color.darkGray);

  paintGrid(g2,gridWidth, gridHeight);

  g2.setColor(Color.red);
  Line2D line = new Line2D.Float(20, 50, 250, 260);               
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  //g2.draw(line); //pending       

  g2.dispose();

}

private void paintGrid(Graphics g, int gridWidth, int gridHeight)
{

  for(int i=20; i<gridWidth+20; i=i+10)
  {      
      g.drawLine(i, 50, i, gridHeight+49);          
  }      

  for(int i=50; i<gridHeight+50; i=i+10)
  {      
      g.drawLine(20, i, 1259, i);          
  }      
}

//Thanks for comments!! Here is the event handler to add.
This must be added to every memu item drawn over the grid

private void jMenu2MenuDeselected(javax.swing.event.MenuEvent evt) {
    repaint();
}
  • 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-30T21:30:48+00:00Added an answer on May 30, 2026 at 9:30 pm

    When the menu is closed call reprint to the window.

    Don’t call paint(getGraphics()). Instead call repaint() because this informs the super component that it needs to redraw as well.

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

Sidebar

Related Questions

how can i change the background color of a picture saving from a picturebox
I see these terms used interchangeably as the global environment for the DOM. What
Thing is, I don't see these ENUMs producing pull-down menus in CakePHP scaffolding, so
When I study about cloud-computing, I usually see these terms: on-premise, off-premise applications. I
I have a running JVM with two threads. Is it possible to see these
I see an application have used Log.info = some info where are these logs
I have been coming across these two words more often but i didn't see
See section /* Common Classes */ of this page. http://webdesign.about.com/od/css/a/master_stylesht_2.htm are these css classes
I see some app on Play Store, when install these apps auto add an
Click here to see what I mean.. What could prevent these two from sitting

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.