It's not a secret anymore!*
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 Murach's Java Servlets and JSP this week in the Servlets 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.
subject: can't understand JComponent
Similar Threads
paintComponent JPanel
Messagebox with Mouseevent
I want to insert Data into the pie chart.I have put the code to gernate the Pie
Help w/ displaying several .PNG files