aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Setting background when extending JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting background when extending JPanel" Watch "Setting background when extending JPanel" New topic
Author

Setting background when extending JPanel

Dewang Shah
Greenhorn

Joined: Mar 14, 2001
Posts: 10
I have written a class that extends JPanel, and am adding it to a JTabbedPane. However I am unable to set the background color for the JPanel. The call to setBackground(Color) does not give any error but does not set the background either.
If I dont extend JPanel and add the JPanel directly to the JTabbedPane(rather than my class) ,then the background is set.
What could be the reason??
When extending the class, other methods like setFont() and setToolTipText() are working fine...
Paul Bailey
Ranch Hand

Joined: Oct 20, 2000
Posts: 91
Sounds like a bug. try reporting it to the bug database http://developer.java.sun.com/developer/bugParade/index.jshtml
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I don't know if this will help or not. You said you are adding the class that extends JPanel to a JTabbedPane. Then are you adding components to the JPanel on the JTabbedPane or have you somehow managed to lay another panel on top that is covering up the background?? Just an idea. Make sure that your contentPane is the JPanel you are adding to the JTabbedPane.
If this is not the reason, I am sorry I do not know.

------------------
Happy Coding,
Gregg Bolinger


GenRocket - A Test Data Generation Platform
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

If your new JPanel overrides paintComponent( Graphics g ), be sure to call super.paintComponent( g ). Either that, or at the start of the new paintComponent method do :


Hope this helps,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting background when extending JPanel
 
Similar Threads
JTabbedPane color
question about background colors in jtabbedpane
JTable -background color
Image In JTabbedPane Background
Highlight the Selected Tab in JTabbed Pane