• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why Jpanel is not inserted in jframe  RSS feed

 
Abhishek KumarSoni
Ranch Hand
Posts: 61
Chrome Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I pick this code from Head first Java

but just a Jframe is appearing no Jpanel no green color circle??What is wrong with code
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should override paintComponent() instead of paintComponents(), like so:

Notice also the call to super.paintComponent().
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely it should have protected access?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should, actually. It's of course legal to increase visibility to public, but unnecessary. Good catch
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!