File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Of setbackground for JComponent.

 
firstimer too
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch. Please UseAMeaningfulSubjectLine, UseCodeTags and IsolateTheProblem.
And we have a naming policy.

Just look at the documentation: javadoc.
 
Rob Camick
Ranch Hand
Posts: 2476
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 4632
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic