File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes can't understand JComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "can Watch "can New topic

can't understand JComponent

budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
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( 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

Joined: Nov 18, 2008
Posts: 433
JComponent is not opaque and does not draw its background. JPanel is opaque and is recommend as base class for creating own components.
It is sorta covered in the JavaRanch Style Guide.
subject: can't understand JComponent
It's not a secret anymore!