Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By FALL3N

Thread: Removing old selection Rectangle when new item selected

  1. #1
    FALL3N is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Removing old selection Rectangle when new item selected

    Hi, I have a menu that shows different items, and when the user clicks an item, they select it and a red Rectangle is drawn around it.

    Now, that works fine, but my problem is that when I select a Shape, and then a new Shape, the old selection square is still there when the new one is drawn... (btw, the red Rectangle is a 'Rectangle' Object). I want the old selection Rectangle to disappear when a new shape is selected... I looked in the APIs and stuff for Rectangle objects, and Graphics2D, and I didn't see a .remove(), .destroy(), .erase(), .delete() or anything similar that I could see... How can I make the old selection rectangle disappear when a new item is selected?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Removing old selection Rectangle when new item selected

    Are you drawing this in a paint(...) or paintComponent(...) method? If so, you should call the super method as the first method call. This paints the component's background and erases any old drawing.

  3. #3
    FALL3N is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Re: Removing old selection Rectangle when new item selected

    I am drawing this in a paint(...) method. Oh, that sounds like exactly the answer I was looking for... but I just tried it, and it isn't doing what you say... I called the super method paint() from within paint() and I tried calling the super methods of paint and paintComponent from within paintComponent... what should I be doing if not this?

    btw,
    ur username =

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Removing old selection Rectangle when new item selected

    I'm not sure. As for me, I'd like you to show us more and tell us more, preferably an SSCCE if you can make one.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Removing old selection Rectangle when new item selected

    Moved from Advanced Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    FALL3N is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Re: Removing old selection Rectangle when new item selected

    oh, sorry to waste ur time, in making a new sscce I was able to solve the problem I was having.. thanks for the advice!
    Fubarable likes this.

Similar Threads

  1. unselected item from selected list
    By prasathbala in forum NetBeans
    Replies: 0
    Last Post: 01-10-2012, 05:41 AM
  2. JComboBox-selected item
    By nenadm in forum AWT / Swing
    Replies: 1
    Last Post: 05-27-2011, 12:58 PM
  3. Removing an Item from an array
    By chris1 in forum New To Java
    Replies: 3
    Last Post: 04-25-2011, 06:59 AM
  4. Why wont my JSP page display my selected item?
    By system32 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-01-2011, 04:02 PM
  5. How to get the selected item from combox
    By man4ish in forum AWT / Swing
    Replies: 5
    Last Post: 12-30-2009, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •