Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default SetBackground for JComponent

    I have the following 3 pages of code!! It is a paint application (like MS paint)
    PaintingFrame
    PaintingCanvas
    MainPaint.

    The application is run by executing the MainPaint which basically just calls main method.

    I have been trying t set the background color for PaintingCanvas. have tried all sorts of things and nothing has wrked out.
    Can someone pleaaase study the code and suggest a method ASAP. It needs to be somewhere in the clear() method.

    ->Also, is it right to add the PaintingCanvas to frame or to the contentpane?

    MAINPAINT
    Java Code:
    public class MainPaint {
      public static void main(String args[]) {
    
        new PaintingFrame();     // creates a window and starts the program
       
      }
    }
    Last edited by Fubarable; 09-12-2010 at 10:13 PM. Reason: Moderator Edit: copyrighted text removed

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

    Default

    Quote Originally Posted by tulasi.neppali View Post
    I have the following 3 pages of code!! It is a paint application (like MS paint)
    PaintingFrame
    PaintingCanvas
    MainPaint.

    The application is run by executing the MainPaint which basically just calls main method.

    I have been trying t set the background color for PaintingCanvas. have tried all sorts of things and nothing has wrked out.
    Can someone pleaaase study the code and suggest a method ASAP. It needs to be somewhere in the clear() method.
    Welcome to the forum. I've taken the liberty of adding code tags to your code so that it will retain its formatting and be readable. To learn to do this yourself, please have a look at my link signature.

    A couple of suggestions to help you get help here:
    1) Rather than post all of your code large volume of here and expect volunteers to go through it and debug it for you, you would do yourself and us a favor by creating a small compilable runnable program that doesn't have all your program's functionality but just tries to solve the issue at hand in a easily understandable and reasonable sized way. This is called creating an SSCCE, and I invite you to read this link or the one in my signature on tips on how to create one of these.
    2) I've often found here that statements like "urgent" or "ASAP" have the opposite effect intended since we are all volunteers helping out on our spare time. No one likes to feel pressured to do work and volunteers especially. If you truly need a solution ASAP, then you should consider heading over to rent a coder and paying for help. Otherwise if you want our help when we can provide it and on our own schedule, we'll be happy to assist; just you may wish to leave statements of urgency out of it.

    Much luck.

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

    Default

    Edit: as to clearing your image, what about simply creating a new Image as you've done before, and then repainting your JComponent?

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

    Default

    Cross-posted here: setbackground-JComponent

    Please read the JavaRanch policies on cross-posting as they apply here as well. On that note, have you posted this question anywhere else?

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

    Default

    Cross posted
    Of setbackground for JComponent. (Swing / AWT / SWT / JFace forum at JavaRanch)

    The marathon code was removed form the cross post by a moderator. Also, the copyright notice in the posted code suggests the OP may not be authorized to post it on a public forum.

    db
    Last edited by DarrylBurke; 09-12-2010 at 10:02 PM. Reason: Missed by 8 minutes!

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

    Default

    Quote Originally Posted by Darryl.Burke View Post
    ... Also, the copyright notice in the posted code suggests the OP may not be authorized to post it on a public forum.

    db
    Indeed. Again, many thanks Darryl!

Similar Threads

  1. Random size of JComponent
    By Karl-von-bahnhof in forum AWT / Swing
    Replies: 0
    Last Post: 04-13-2010, 08:14 PM
  2. Problems with setBackground()
    By Oleg in forum New To Java
    Replies: 6
    Last Post: 03-07-2010, 04:59 PM
  3. JButton.setBackground() Problem
    By ellias2007 in forum AWT / Swing
    Replies: 2
    Last Post: 02-24-2010, 09:49 PM
  4. JComponent gradient background
    By snipered in forum AWT / Swing
    Replies: 0
    Last Post: 12-30-2008, 12:38 AM
  5. polygon-shaped JComponent
    By zenMarko in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 06:06 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
  •