List of usage examples for javax.swing JComponent removeAncestorListener
public void removeAncestorListener(AncestorListener listener)
listener
so that it will no longer receive AncestorEvents
. From source file:Main.java
public static void requestFocusOnDisplay(JComponent c) { final JComponent c2 = c; c2.addAncestorListener(new javax.swing.event.AncestorListener() { public void ancestorAdded(javax.swing.event.AncestorEvent event) { c2.requestFocus();//from ww w. j a v a 2 s.c om c2.removeAncestorListener(this); } public void ancestorRemoved(javax.swing.event.AncestorEvent event) { } public void ancestorMoved(javax.swing.event.AncestorEvent event) { } }); }
From source file:Main.java
/** * Destroys container by destroying its childs structure and removing all * listeners./*from w w w . j a va 2 s .c o m*/ * * @param container * container to destroy */ public static void destroyContainer(final Container container) { for (final Container toDestroy : collectAllContainers(container)) { toDestroy.removeAll(); toDestroy.setLayout(null); for (final MouseListener listener : toDestroy.getMouseListeners()) { toDestroy.removeMouseListener(listener); } for (final MouseMotionListener listener : toDestroy.getMouseMotionListeners()) { toDestroy.removeMouseMotionListener(listener); } for (final MouseWheelListener listener : toDestroy.getMouseWheelListeners()) { toDestroy.removeMouseWheelListener(listener); } for (final KeyListener listener : toDestroy.getKeyListeners()) { toDestroy.removeKeyListener(listener); } for (final ComponentListener listener : toDestroy.getComponentListeners()) { toDestroy.removeComponentListener(listener); } for (final ContainerListener listener : toDestroy.getContainerListeners()) { toDestroy.removeContainerListener(listener); } if (toDestroy instanceof JComponent) { final JComponent jComponent = (JComponent) toDestroy; for (final AncestorListener listener : jComponent.getAncestorListeners()) { jComponent.removeAncestorListener(listener); } } } }
From source file:Main.java
public static void focusOnOpen(final JComponent component) { /*/*from ww w .j a v a2 s .c o m*/ final Window window = SwingUtilities.getWindowAncestor(component); if (window != null) window.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { component.requestFocus(); window.removeWindowListener(this); } }); */ component.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { component.requestFocusInWindow(); component.removeAncestorListener(this); } public void ancestorRemoved(AncestorEvent event) { } public void ancestorMoved(AncestorEvent event) { } }); }
From source file:Main.java
private static void disposeComponent(JComponent component) { if (component == null) { return;//from ww w . java2 s. c o m } component.removeNotify(); FocusListener[] focusListeners = component.getFocusListeners(); for (int i = 0; i < focusListeners.length; i++) { component.removeFocusListener(focusListeners[i]); } KeyListener[] keyListeners = component.getKeyListeners(); for (int i = 0; i < keyListeners.length; i++) { component.removeKeyListener(keyListeners[i]); } AncestorListener[] ancestorListener = component.getAncestorListeners(); for (int i = 0; i < ancestorListener.length; i++) { component.removeAncestorListener(ancestorListener[i]); } ComponentListener[] componentListeners = component.getComponentListeners(); for (int i = 0; i < componentListeners.length; i++) { component.removeComponentListener(componentListeners[i]); } HierarchyListener[] hierarchyListeners = component.getHierarchyListeners(); for (int i = 0; i < hierarchyListeners.length; i++) { component.removeHierarchyListener(hierarchyListeners[i]); } HierarchyBoundsListener[] hierarchyBoundsListeners = component.getHierarchyBoundsListeners(); for (int i = 0; i < hierarchyBoundsListeners.length; i++) { component.removeHierarchyBoundsListener(hierarchyBoundsListeners[i]); } InputMethodListener[] inputMethodListeners = component.getInputMethodListeners(); for (int i = 0; i < inputMethodListeners.length; i++) { component.removeInputMethodListener(inputMethodListeners[i]); } MouseListener[] mouseLisetners = component.getMouseListeners(); for (int i = 0; i < mouseLisetners.length; i++) { component.removeMouseListener(mouseLisetners[i]); } MouseMotionListener[] mouseMotionLisetners = component.getMouseMotionListeners(); for (int i = 0; i < mouseMotionLisetners.length; i++) { component.removeMouseMotionListener(mouseMotionLisetners[i]); } MouseWheelListener[] mouseWheelListeners = component.getMouseWheelListeners(); for (int i = 0; i < mouseWheelListeners.length; i++) { component.removeMouseWheelListener(mouseWheelListeners[i]); } PropertyChangeListener[] propertyChangeListeners = component.getPropertyChangeListeners(); for (int i = 0; i < propertyChangeListeners.length; i++) { component.removePropertyChangeListener(propertyChangeListeners[i]); } VetoableChangeListener[] vetoableChangeListener = component.getVetoableChangeListeners(); for (int i = 0; i < vetoableChangeListener.length; i++) { component.removeVetoableChangeListener(vetoableChangeListener[i]); } }