Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JComponent;

import javax.swing.SwingUtilities;

public class Main {
    /**
     * Repaints the parent of the given component. If the parent is null, the component itself is repainted.
     * 
     * @param    component      The component whose parent will be repainted.
     */
    public static void repaintParent(JComponent component) {

        // Get the parent of the component.
        JComponent parentComponent = (JComponent) SwingUtilities.getAncestorOfClass(JComponent.class, component);

        // Could we find a parent?
        if (parentComponent != null) {
            // Repaint the parent.
            parentComponent.revalidate();
            parentComponent.repaint();
        } else {
            // Repaint the component itself.
            component.revalidate();
            component.repaint();
        }

    }
}