Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't understand JComponent

 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was making a jcomponent and inside it i drew a rectangle . i wanted to set the background color of the JComponent as red or anything but when i write setBackground(Color.red) and execute the code the color is not set . Can somebody explain why ? My hunch is that it has something to do with the opaque property . Please expalin. here's the code



>
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JComponent is not opaque and does not draw its background. JPanel is opaque and is recommend as base class for creating own components.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic