![JAR search and dependency download from the Maven repository](/logo.png)
bibliothek.gui.dock.support.lookandfeel.LookAndFeelUtilities Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docking-frames-common Show documentation
Show all versions of docking-frames-common Show documentation
DockingFrames is an open source Java Swing docking framework, licenced under LGPL 2.1.
This is the same distribution as the original distribution (http://www.docking-frames.org/), only reinstalled in maven
package bibliothek.gui.dock.support.lookandfeel;
import java.awt.Component;
import java.awt.Container;
import java.awt.Window;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
/**
* A set of methods that used to update the {@link LookAndFeel} of {@link Component}s.
* @author Benjamin Sigg
*/
public class LookAndFeelUtilities {
/**
* Updates the look and feel for all windows that can be found through
* the collection of components.
* @param components a set of known components
*/
public static void updateUI( Collection components ){
Set visit = new HashSet();
for( Component component : components ){
component = getAncestor( component );
Window window = SwingUtilities.getWindowAncestor( component );
if( window != null )
change( window, visit );
else
change( component, visit );
}
}
/**
* Gets the one parent of component
which does not have a
* parent itself.
* @param component some component
* @return a parent of component
or component
itself.
*/
private static Component getAncestor( Component component ){
Container parent = component.getParent();
if( parent == null )
return component;
return getAncestor( parent );
}
/**
* Updates the look and feel of base
and all its
* children. Recursively goes through all {@link Window}s that
* are owned by base
(assuming base
* is itself a Window
).
* @param base the root of a component-tree
* @param visit the set of roots that were already visited, base
* is added to this set and if base
was already in the set,
* then this method returns immediately
*/
private static void change( Component base, Set visit ){
if( visit.add( base )){
SwingUtilities.updateComponentTreeUI( base );
if( base instanceof Window ){
Window window = (Window)base;
for( Window child : window.getOwnedWindows() )
change( child, visit );
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy