Java JComponent Container invokeRepaintOnLayeredRoot(Component leaf, boolean everything)

Here you can find the source of invokeRepaintOnLayeredRoot(Component leaf, boolean everything)

Description

If the given component is part of a JLayeredPane the lowest layer of that JLayeredPane is used for the repaint; otherwise the component itself.

License

LGPL

Declaration

public static void invokeRepaintOnLayeredRoot(Component leaf,
        boolean everything) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.awt.*;
import javax.swing.*;

public class Main {
    /**/*from   w w w. j ava2 s.  c  om*/
     * If the given component is part of a JLayeredPane the lowest layer
     * of that JLayeredPane is used for the repaint; otherwise the component itself.
     * The repaint area is restricted to the leaf area; exception: flag everything is true.
     */
    public static void invokeRepaintOnLayeredRoot(Component leaf,
            boolean everything) {
        // very dodgy workaround for being in a layered pane
        Component con = leaf.getParent();
        if (con != null && con instanceof JLayeredPane) {
            JLayeredPane lp = (JLayeredPane) con;
            Component[] cs = null;
            synchronized (leaf.getTreeLock()) {
                cs = lp.getComponentsInLayer(lp.lowestLayer());
            }
            if (cs != null && cs.length > 0)
                con = cs[0];
            else
                con = leaf;

            // otherwise, when repaint is invoked normally
            // while we are in a higher layer of a layered pane
            // display flickers sometime

        } else {
            con = leaf;
        }

        if (everything || con == leaf)
            con.repaint();
        else {
            Rectangle r = leaf.getBounds();
            con.repaint(r.x, r.y, r.width, r.height);
        }
    }
}

Related

  1. getTopAncestor(JComponent start)
  2. getTopLevelContainer(JComponent component)
  3. getWindow(final JComponent comp)
  4. getWindow(JComponent c)
  5. getWindowLocation(JComponent start)
  6. isCopyEnabled(JComponent targetComponent)
  7. isPasteEnabled(JComponent targetComponent)
  8. rootPaneForComponent(Component comp)
  9. widgetsEnable(boolean flag, JComponent... comps)