Java tutorial
//package com.java2s; /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ import sun.awt.SunToolkit; import java.awt.Component; import javax.swing.JComponent; import javax.swing.RepaintManager; public class Main { /** * The {@code clientProperty} key for delegate {@code RepaintManager} */ private static final Object DELEGATE_REPAINT_MANAGER_KEY = new StringBuilder("DelegateRepaintManagerKey"); /** * Returns delegate {@code RepaintManager} for {@code component} hierarchy. */ public static RepaintManager getDelegateRepaintManager(Component component) { RepaintManager delegate = null; if (Boolean.TRUE == SunToolkit.targetToAppContext(component).get(DELEGATE_REPAINT_MANAGER_KEY)) { while (delegate == null && component != null) { while (component != null && !(component instanceof JComponent)) { component = component.getParent(); } if (component != null) { delegate = (RepaintManager) ((JComponent) component) .getClientProperty(DELEGATE_REPAINT_MANAGER_KEY); component = component.getParent(); } } } return delegate; } }