• 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
Sheriff
Posts: 53779
128
  • 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: 4589
6
Java Python 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!