aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Of setbackground for JComponent. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Of setbackground for JComponent." Watch "Of setbackground for JComponent." New topic
Author

Of setbackground for JComponent.

firstimer too
Greenhorn

Joined: Sep 12, 2010
Posts: 1
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?

[RP] removed long unreadable code after several requests [/RP]
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Welcome to the JavaRanch. Please UseAMeaningfulSubjectLine, UseCodeTags and IsolateTheProblem.
And we have a naming policy.

Just look at the documentation: javadoc.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
setbackground for JComponent.


By default a JComponent doesn't do any custom painting. You have two choices:

a) override the paintComponent() method of your custom class to do the background painting yourself

b) extend JPanel instead of JComponent and you get the default background painting.

In the future post a SSCCE when you have a problem. You posted too much code to read.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Wouter Oet wrote:Welcome to the JavaRanch. Please UseAMeaningfulSubjectLine, UseCodeTags and IsolateTheProblem.
And we have a naming policy.

Just look at the documentation: javadoc.

Thanks for doing my work

Rob Camick wrote:In the future post a SSCCE when you have a problem. You posted too much code to read.

Indeed. Combined with the lack of code tags this is a definite case of TLDR


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

"firsttimer too", I've removed the long unreadable code part after several requests from others about it not being readable and hindering their ability to read this thread. If you still need to after reading Rob Camick's post you can repeat the relevant parts, and in code tags.

I also removed the being grateful part of the subject, as it didn't add anything since everybody is always grateful
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://www.java-forums.org/awt-swing/32435-setbackground-jcomponent.html
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

So in addition to the FAQ entries Wouter posted, there's also BeForthrightWhenCrossPostingToOtherSites. You should really read http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Of setbackground for JComponent.