List of usage examples for java.awt.event ContainerEvent getContainer
public Container getContainer()
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(); buttonPanel.addContainerListener(new ContainerListener() { public void componentAdded(ContainerEvent e) { displayMessage(" added to ", e); }/*from w w w . ja v a 2 s. c o m*/ public void componentRemoved(ContainerEvent e) { displayMessage(" removed from ", e); } void displayMessage(String action, ContainerEvent e) { System.out.println(((JButton) e.getChild()).getText() + " was" + action + e.getContainer().getClass().getName()); } }); buttonPanel.add(new JButton("A")); frame.add(buttonPanel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(true); buttonPanel.addContainerListener(new ContainerListener() { public void componentAdded(ContainerEvent e) { displayMessage(" added to ", e); }/*from w w w. j ava2 s .c o m*/ public void componentRemoved(ContainerEvent e) { displayMessage(" removed from ", e); } void displayMessage(String action, ContainerEvent e) { System.out.println(((JButton) e.getChild()).getText() + " was" + action + e.getContainer().getClass().getName()); } }); buttonPanel.add(new JButton("A")); frame.add(buttonPanel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:UsingContainerListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(); buttonPanel.addContainerListener(new ContainerListener() { public void componentAdded(ContainerEvent e) { displayMessage(" added to ", e); }/*from w ww.ja va2 s .c om*/ public void componentRemoved(ContainerEvent e) { displayMessage(" removed from ", e); } void displayMessage(String action, ContainerEvent e) { System.out.println(((JButton) e.getChild()).getText() + " was" + action + e.getContainer().getClass().getName()); } }); buttonPanel.add(new JButton("A")); frame.add(buttonPanel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ContainerEventDemo.java
void displayMessage(String action, ContainerEvent e) { display.append(((JButton) e.getChild()).getText() + " was" + action + e.getContainer().getClass().getName() + newline);//from ww w .jav a2 s .co m display.setCaretPosition(display.getDocument().getLength()); }
From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java
/** * Remove the removed component from the hierarchy. * {@inheritDoc}/* w w w . ja v a 2 s. c om*/ */ public void componentRemoved(ContainerEvent event) { checkDispatchThread(); removeComponent(event.getChild(), event.getContainer()); }
From source file:org.eclipse.jubula.rc.swing.listener.ComponentHandler.java
/** * Checks if there is already a listener of an AUTHierarchy instance * at the container of the added component. If there is no listener and if the * container is known by the AUTHierarchy, the component will be added * to the AUTHierarchy via this method by calling the componentAdded method * of the AUTHierarchy. <br> <br> * <b>Note:</b> This is only a workaround, because some applications may * clean the listeners of the container inclusive the listeners, so * we cannot notice added components anymore. * Therefor the global AWTEventListener at the Toolkit has to check this. * /*from w ww . ja va2s. com*/ * @param event the ContainerEvent.COMPONENT_ADDED */ private void checkContainerListener(ContainerEvent event) { if (!hasListener(event.getContainer(), ContainerListener.class) && (autHierarchy.getHierarchyContainer(event.getContainer()) != null)) { if (log.isInfoEnabled()) { log.info("ComponentHandler called: autHierarchy.componentAdded"); //$NON-NLS-1$ } autHierarchy.componentAdded(event); } }