Java JSP Application Hosting Web Hosting, website hosting, web site hosting , web page hosting Apache, PHP, MySQL, PERL, servlets Java, JSP  Java JSP Application Hosting Web Hosting website hosting, web site hosting, web page hosting Apache, PHP, MySQL, PERL, servlets Java, JSP,Python Java JSP Application Hosting Web Hosting website hosting, web site hosting, web page hosting Apache, PHP, MySQL, PERL, servlets Java, JSP,Python Java JSP Application Hosting Web Hosting website hosting, web site hosting, web page hosting Apache, PHP, MySQL, PERL, servlets Java, JSP,Python Java JSP Application Hosting Web Hosting website hosting, web site hosting, web page hosting, Apache, PHP, MySQL, PERL, servlets Java, JSP,Python
Java JSP Application Hosting Web Hosting, website hosting, web site hosting, web page hosting, Apache, PHP, MySQL, PERL, servlets Java, JSP, Python Java JSP Application Hosting Web Hosting, website hosting, web site hosting, web page hosting, Apache, PHP, MySQL, PERL, servlets Java, Python,JSP
Java JSP Application Hosting Web Hosting Sign-Up Java JSP Application Hosting Fund Raising, Fundraising, web hosting, website hosting, web site hosting  Java JSP Application Hosting Resellers web hosting, website hosting, web site hosting Java JSP Application Hosting EZ Site Control Panel for web hosting,website hosting, web site hosting
Java JSP Application Hosting Web Hosting, website hosting, web site hosting , web page hosting Apache, PHP, MySQL, PERL, servlets Java, Python,JSP,  Fundraising
Java JSP Application Hosting Fund Raising, Fundraising, web hosting, website hosting, web site hosting
WWW.

Call Us Toll-Free
(877) 256-0328

Outside USA
1 - (201) 505-0430

Java JSP Application Hosting Welcome Java JSP Application Hosting Web Hosting Plans Overview , Fund Raising, Fundraising, web hosting, website hosting, web site hosting Java JSP Application Hosting Fund Raising, Fundraising, web hosting Java JSP Application Hosting Resellers, web Hosting Java JSP Application Hosting Web Design, web Hosting Java JSP Application Hosting Extra Services,  web Hosting Java JSP Application Hosting Traffic Booster, web hosting Java JSP Application Hosting Traffic Booster, web hosting Java JSP Application Hosting Technical Support,  web Hosting Java JSP Application Hosting webmaster tips,  web Hosting Java JSP Application Hosting 30 Day Money Back, web hosting Java JSP Application Hosting Legal Notices for Web Hosting Java JSP Application Hosting Glossary Computer Terms for web Hosting Java JSP Application Hosting Contact Information - web hosting

Site Map
Java JSP Application Hosting Web Hosting, website hosting, web site hosting , web page hosting Apache, PHP, MySQL, PERL, servlets Java, Python, JSP Java JSP Application Hosting Java JSP Application Hosting Java JSP Application Hosting Java JSP Application Hosting Java JSP Application Hosting How to Write a Container Listener (The Java™ Tutorials > Creating a GUI with JFC/Swing > Writing Event Listeners)
Trail: Creating a GUI with JFC/Swing
Lesson: Writing Event Listeners
Section: Implementing Listeners for Commonly Handled Events
Home Page > Creating a GUI with JFC/Swing > Writing Event Listeners
How to Write a Container Listener
Container events are fired by a Container just after a component is added to or removed from the container. These events are for notification only — no container listener need be present for components to be successfully added or removed.

The following example demonstrates container events. By clicking Add a button or Remove a button, you can add buttons to or remove them from a panel at the bottom of the window. Each time a button is added to or removed from the panel, the panel fires a container event, and the panel's container listener is notified. The listener displays descriptive messages in the text area at the top of the window.

A screenshot which demonstrates container events


Try this: 
  1. Click the Launch button to run ContainerEventDemo using Java™ Web Start (download JDK 6). Alternatively, to compile and run the example yourself, consult the example index.
    Launches the ContainerEventDemo example
  2. Click the button labeled Add a button.
    You will see a button appear near the bottom of the window. The container listener reacts to the resulting component-added event by displaying "JButton #1 was added to javax.swing.JPanel" at the top of the window.
  3. Click the button labeled Remove a button.
    This removes the most recently added button from the panel, causing the container listener to receive a component-removed event.

You can find the demo's code in ContainerEventDemo.java. Here is the demo's container event handling code:

public class ContainerEventDemo ... implements ContainerListener ... {
    ...//where initialization occurs:
	buttonPanel = new JPanel(new GridLayout(1,1));
	buttonPanel.addContainerListener(this);
    ...
    public void componentAdded(ContainerEvent e) {
	displayMessage(" added to ", e);
    }

    public void componentRemoved(ContainerEvent e) {
	displayMessage(" removed from ", e);
    }

    void displayMessage(String action, ContainerEvent e) {
	display.append(((JButton)e.getChild()).getText()
		       + " was"
		       + action
		       + e.getContainer().getClass().getName()
		       + newline);
    }
    ...
}

The Container Listener API

The ContainerListener Interface

The corresponding adapter class is ContainerAdapter.

Method Purpose
componentAdded(ContainerEvent) Called just after a component is added to the listened-to container.
componentRemoved(ContainerEvent) Called just after a component is removed from the listened-to container.

The ContainerEvent Class

Method Purpose
Component getChild() Returns the component whose addition or removal triggered this event.
Container getContainer() Returns the container that fired this event. You can use this instead of the getSource method.

Examples that Use Container Listeners

The following table lists the examples that use container listeners.

Example Where Described Notes
ContainerEventDemo This section Reports all container events that occur on a single panel to demonstrate the circumstances under which container events are fired.
Previous page: How to Write a Component Listener
Next page: How to Write a Document Listener
 
 
 

Add to My Yahoo!

XML icon

Add to Google

 

 

 

 

 

 

 

 

 

 

 

JSP Servlets Tomcat mysql Java JSP Servlets Tomcat mysql Java JSP Servlets Tomcat mysql Java JSP Servlets Tomcat mysql Java JSP at JSP.aldenWEBhosting.com Servlets at servlets.aldenWEBhosting.com Tomcat at Tomcat.aldenWEBhosting.com mysql at mysql.aldenWEBhosting.com Java at Java.aldenWEBhosting.com Web Hosts Portal Web Links Web Links Web Hosting JSP Solutions Web Links JSP Solutions Web Hosting Servlets Solutions Web Links Servlets Solutions Web Hosting Web Links Web Links . . .
.
.
. .
.
. .
. . . . . . . . . . . jsp hosting servlets hosting web hosting web sites designed cheap web hosting web site hosting myspace web hosting