Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.awt.Component;
import java.awt.Container;

public class Main {
    /**
     * Workaround for bug in swing invalidate/validate concept. Swing is caching
     * component sizes and clearing that cache once invalidate is called, which is
     * fine. But in case a validate is in progress and part of the ancestor tree
     * is already layouted based on old sizes then the caches are already set, but
     * the valid flag is still false. Therefore this method can be called which
     * will invalidate all ancestors *including* those that are still invalid in
     * order to clear all size caches. see also invalidateAncestors()
     */
    public static void invalidateSubtree(Component c) {
        invalidateSubtreeRec(c);
    }

    private static void invalidateSubtreeRec(Component c) {
        if (c != null && c.isVisible()) {
            c.invalidate();
            if (c instanceof Container) {
                for (Component child : ((Container) c).getComponents()) {
                    invalidateSubtreeRec(child);
                }
            }
        }
    }
}