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

  • Home
  • SEARCH
  • 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 8121167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:23:51+00:00 2026-06-06T05:23:51+00:00

I am having problem with drawing multiple lines during repaint. The code is as

  • 0

I am having problem with drawing multiple lines during repaint. The code is as follows:

public void paintComponent(Graphics g){
    Graphics2D g2d = (Graphics2D) g;

    Map<Device, Device> devMap = matchEncDec();
    if(devMap != null){
        Iterator<?> it = devMap.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<Device, Device> pair =  (Entry<Device, Device>) it.next();
            it.remove();

            g2d.setColor(Color.BLUE);
            g2d.drawLine(pair.getKey().getLocationOnScreen().x + 150, pair.getKey().getLocationOnScreen().y, 
                    pair.getValue().getLocationOnScreen().x + 150, pair.getValue().getLocationOnScreen().y);

            g2d.drawLine(50, 50, 500, 550);
        }
    }
}

it draws line only for the last pair in the HashMap and the test line that i added.
Thanks in advance for help.

  • 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-06T05:23:53+00:00Added an answer on June 6, 2026 at 5:23 am

    Don’t remove the pair from the iterator.

    it.remove();
    

    This is an un-neccesary step if it’s a temporary hashmap, and it’s a critical problem if it’s a reused hashmap. This removes the item from the underlying hashmap. So if matchEncDec() is returning a hashmap that is being reused, you will only paint each line once because the pair will be removed from the hashmap once it gets painted.

    It would be helpful to see the matchEncDec() method, but I would just be checking to see if you are returning a reference to the same hashmap with each call. If that’s the case, then this is definitely the problem.

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

Sidebar

Related Questions

I'm having a graphics problem on drawing lines in Flash Player, where two lines
I am having a problem of drawing a character in a CATextLayer such that
I'm having a problem with drawing zoomed in contour maps. The problem is best
I'm custom drawing a menu item in a MenuStrip . The problem I'm having
Whilst drawing on a SurfaceView, I'm having a problem intercepting a 'back' key press.
I am learning OpenGL and having a problem with gluPerspective. Here is the code
I'm having a very strange problem with XNA/OpenGL on Windows Phone 7. I'm drawing
I am having trouble drawing one pixel wide lines. All lines are perfectly horizontal
I'm having a bit of a problem, drawing text on an image. When I'm
I'm having problems with drawing rotated images on PDF, my output is worse. My

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.