• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting background when extending JPanel

 
Dewang Shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic