• 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

Painting background in JComponent

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having some trouble understanding what is going on with JComponent painting.
The docs seem to indicate that if the component is opaque that the background is painted with the background colour. But I hvae found that JComponent never paints the background properly!
I have made my own component that derives from JComponent.
I override the PaintComponent method and the first line of my paintComponet calls super.paintComponent. I also called setOpaque(true) in the constructor, and just to be safe override isOpaque to always return false.
when my component is painted the "background" is painted with garbage graphics left over from the last thing that painted. I expected it to be filled with the background colour. If I do not make the compinent opaque then I do get a clean background colour of my frame showing through. So clearly JComponent is painting something for the background - but it is not working. This happens in 1.3.1 and the 1.4 beta.
I can solve my problem by deriving from JPanel instead of JComponent or by explicitly painting the background myself in the paintComponent methoid.. But I would like to understand why Jcomponent is behaving this way.
Thanks in advance for your help,
Scott
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic