Window System in NetBeans Platform 6.9

Automatic window lifecycle management

A further major advantage of the NetBeans Window System is that it provides
a WindowManager that controls the lifecycle of all the windows defined in the
application. The WindowManager notifies all TopComponents about state changes
using callback methods, listed as follows:



Let’s illustrate this lifecycle via an example that logs all the callback methods to the
output window of NetBeans IDE, which is your development environment on top of
the NetBeans Platform 6.9.



  1. Create a new NetBeans Platform 6.9 application and name it
    WindowSystemExamples.

  2. Add a new module named LifeCycle, with Code Name Base
    com.netbeansrcp.lifecycle.

  3. Add a TopComponent, with Class Name Prefix prefix LifeCycleDemo,
    making sure to indicate that it should be automatically opened in the editor
    area at application startup.

  4. Override the lifecycle methods as follows:



public void componentOpened() {
super.componentOpened();
System.out.println(“componentOpened()”);
}
protected void componentShowing() {
super.componentShowing();
System.out.println(“componentShowing()”);
}
protected void componentActivated() {
super.componentActivated();
System.out.println(“componentActivated()”);
}
@Override
protected void componentDeactivated() {
super.componentDeactivated();
System.out.println(“componentDeactivated()”);
}
@Override
protected void componentHidden() {
super.componentHidden();
System.out.println(“componentHidden()”);
}
@Override
public void componentClosed() {
super.componentClosed();
System.out.println(“componentClosed()”);
}


Start the new application. The TopComponent LifeCyleDemoTopComponent is
automatically opened at startup. Select the TopComponent and inspect the output
in the NetBeans IDE Output Window. You should see the following:



componentOpened()
componentShowing()
componentActivated()


The TopComponent has passed the first half of its lifecycle and is now activated.


Close the LifeCyleDemoTopComponent and inspect the output again, to understand
the second half of the TopComponent lifecycle. You should see the following output:



componentHidden()
componentDeactivated()
componentClosed()


You have learned that the TopComponent’s lifecycle is automatically controlled
by the NetBeans Platform 6.9. Between the start and the end of the TopComponent’s
lifecycle are six different states, all managed by the NetBeans Platform 6.9, and with
notifications sent via callbacks.

NetBeans Articles

Pages: 1 2 3 4

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!