Java Code Examples for java.awt.event.HierarchyEvent#getChanged()

The following examples show how to use java.awt.event.HierarchyEvent#getChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteAWTHierarchyListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void eventDispatched(AWTEvent event) {
    HierarchyEvent e = (HierarchyEvent) event;
    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
        Component c = e.getChanged();
        Container p = c.getParent();
        if (p == null) {
            // Component was removed from the hierarchy
            components.remove(c);
        } else {
            Throwable t = new RuntimeException();
            StringWriter sw = new StringWriter();
            t.printStackTrace(new PrintWriter(sw));
            String stackTrace = sw.toString();
            String stackLine = getComponentAddStackLine(stackTrace);
            components.put(c, stackLine);
        }
    }
}
 
Example 2
Source File: JBRCustomDecorations.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
static void install( JRootPane rootPane ) {
	if( !isSupported() )
		return;

	// check whether root pane already has a parent, which is the case when switching LaF
	if( rootPane.getParent() != null )
		return;

	// Use hierarchy listener to wait until the root pane is added to a window.
	// Enabling JBR decorations must be done very early, probably before
	// window becomes displayable (window.isDisplayable()). Tried also using
	// "ancestor" property change event on root pane, but this is invoked too late.
	HierarchyListener addListener = new HierarchyListener() {
		@Override
		public void hierarchyChanged( HierarchyEvent e ) {
			if( e.getChanged() != rootPane || (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0 )
				return;

			Container parent = e.getChangedParent();
			if( parent instanceof Window )
				install( (Window) parent );

			// use invokeLater to remove listener to avoid that listener
			// is removed while listener queue is processed
			EventQueue.invokeLater( () -> {
				rootPane.removeHierarchyListener( this );
			} );
		}
	};
	rootPane.addHierarchyListener( addListener );
}