• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Of setbackground for JComponent.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.java-forums.org/awt-swing/32435-setbackground-jcomponent.html
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic