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 javax.swing.JComponent;

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 invalidateSubTree()
     */
    public static void invalidateAncestors(Component c) {
        if (c != null) {
            while (true) {
                c.invalidate();
                c = c.getParent();
                if (c == null) {
                    break;
                }
                if (c instanceof JComponent && ((JComponent) c).isValidateRoot()) {
                    break;
                }
            }
        }
    }
}