Results 1 to 5 of 5
  1. #1
    java25 is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Java Draw with multiple colors

    Hi,

    I have a problem when I'm changing again the color of a graphics object with g.setColor(); it changes the color of already drown parts too.

    What do I have to do if I want the already drown parts to remain the same, and only what I will draw next to be different?

    Thanks !

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Java Draw with multiple colors

    Please show your code.
    The setColor() method should not change the colors of previously drawings.

    Every time you draw something, you must set the color you want before you draw.

  3. #3
    java25 is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: Java Draw with multiple colors

    Ok thanks, that is a problem with a class that I extend which is not written by me.

    Thank you !

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Java Draw with multiple colors

    If you can't change the code then I have no other suggestions.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: Java Draw with multiple colors

    that is a problem with a class that I extend which is not written by me.
    Then your code should look something like:
    Java Code:
    public void paintComponent(Graphics g);
    {
        super.paintComponent(g);
    
        Color original = g.getColor();
        g.setColor(....);
        // draw something
        g.setColor(original);
    }

Similar Threads

  1. Multiple colors in print-statement
    By schutter07 in forum New To Java
    Replies: 8
    Last Post: 11-20-2010, 11:46 AM
  2. One controller with multiple buttons and colors
    By Cutter in forum New To Java
    Replies: 5
    Last Post: 01-24-2010, 06:47 PM
  3. Trying to Draw Multiple Components
    By habester in forum New To Java
    Replies: 1
    Last Post: 11-09-2009, 11:06 PM
  4. How do I use multiple background colors?
    By trbox in forum New To Java
    Replies: 1
    Last Post: 09-02-2008, 01:00 PM
  5. how to set multiple colors in a JtextArea
    By valery in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2007, 05:12 PM

Posting Permissions

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