Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is addNotify();?

I've tried to find a laymans definition of addNotify() but I can't really get any answer using Google.

As far as I know, when overriding addNotify() in my class, I should call super.addNotify(); and then do whatever else afterward.

My question is, does addNotify() run automatically? What is it's purpose and what happens when I override it and furthermore, why would I ever want to override this method?

Thank's.

like image 269
Space Ghost Avatar asked Mar 20 '13 09:03

Space Ghost


People also ask

What is the use of requestFocus in Java?

requestFocus() makes a request that the given Component gets set to a focused state. This method requires that the component is displayable, focusable, visible and have all it's ancestors be visible too.


1 Answers

My question is, does addNotify() run automatically?

Yes. The precise where and when depends on the internals of the AWT implementation.

What is it's purpose

It is as described in the javadoc. It is very low level stuff that is part of the "glue" that connects the AWT world to the native windowing world. (I'm being deliberately high-level and vague. If you want the nitty-gritty details, download and read the OpenJDK source code.)

and what happens when I override it

You'd probably break AWT :-)

and furthermore, why would I ever want to override this method?

I can't think of a good reason to do this ... unless you were trying to port AWT to a different operating system or a different native windowing system.

like image 185
Stephen C Avatar answered Oct 05 '22 23:10

Stephen C