This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding overriding JPanel's paintComponent() method  RSS feed

 
simon fletcher
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to alter a JPanel's paintComponent() method without extending the JPanel? Just curious. From my short experience using swing, I'm thinking not but wanted to be sure.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well...to me this is more an OOPS question. Basically, 'overriding' a method in OOP is to provide a new/different behaviour than what the parent provides...so, if our intention is that, then extending and overriding is the right way to do this...
 
Campbell Ritchie
Marshal
Posts: 55681
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simon fletcher wrote:Is it possible to alter a JPanel's paintComponent() method without extending the JPanel? Just curious. From my short experience using swing, I'm thinking not but wanted to be sure.
Try it. I hope you will find it impossible.
 
Randall Twede
Ranch Hand
Posts: 4690
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would bet 100 to your one that you can't. changing the behavior of a method(overriding) is done by extending the class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!