4 Replies - 3196 Views - Last Post: 08 August 2010 - 03:41 PM Rate Topic: -----

#1 Guest_Scopa*


Reputation:

How to reset a Graphics Object, and set drawing background color

Posted 08 August 2010 - 07:04 AM

I am new to Graphics2D, and I want to reset my graphics2D object, by that I mean clear, but I am not sure how.

When I use the clearRect, it makes the background black instead of white, so I think I am doing something wrong.

How should I do this, to get my desired result.

I am drawing a rectangle on a white background, but when I want to reset, it draws the rectangle on a black background.
Is This A Good Question/Topic? 0

Replies To: How to reset a Graphics Object, and set drawing background color

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: How to reset a Graphics Object, and set drawing background color

Posted 08 August 2010 - 08:46 AM

You may want to try couple of things. You could set the background to white again, or you could print out in console the current background, before and after the clearRect function to see what is happening. Spent some time on it and if you can't figure it out you are welcomed to show the code so that others would be able to help.
:)

This post has been edited by PennyBoki: 08 August 2010 - 08:47 AM

Was This Post Helpful? 0
  • +
  • -

#3 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: How to reset a Graphics Object, and set drawing background color

Posted 08 August 2010 - 12:20 PM

Not quite sure what your intention is...but you can always use the dispose() method...
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,257
  • Joined: 27-December 08

Re: How to reset a Graphics Object, and set drawing background color

Posted 08 August 2010 - 02:58 PM

Disposing a Graphics object is never a good idea unless you are dealing with some low-level GUI tasks, as it can mess up the JComponent. Better to start over than dispose of the Graphics.
Was This Post Helpful? 2
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to reset a Graphics Object, and set drawing background color

Posted 08 August 2010 - 03:41 PM

View PostScopa, on 08 August 2010 - 08:04 AM, said:

I am new to Graphics2D, and I want to reset my graphics2D object, by that I mean clear, but I am not sure how.

Don't see any legitimate reason why you would want to do so.... or, more obviousless and no offense, you missed the whole concept

The Graphics2d object is just a pen to use. There is nothing to reset into it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1