create And Install Repaint Window Focus Listener - Java Swing

Java examples for Swing:Window

Description

create And Install Repaint Window Focus Listener

Demo Code

/*//from   ww w  . j  a  va2  s .  co  m
 * Copyright (c) 2009 Kathryn Huxtable and Kenneth Orr.
 *
 * This file is part of the Aqvavit Pluggable Look and Feel.
 *
 * Aqvavit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.

 * Aqvavit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Aqvavit.  If not, see
 *     <http://www.gnu.org/licenses/>.
 * 
 * $Id$
 */
//package com.java2s;

import java.awt.Window;

import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

public class Main {
    public static WindowFocusListener createAndInstallRepaintWindowFocusListener(
            Window window) {
        // create a WindowFocusListener that repaints the window on focus changes.
        WindowFocusListener windowFocusListener = new WindowFocusListener() {
            public void windowGainedFocus(WindowEvent e) {
                e.getWindow().repaint();
            }

            public void windowLostFocus(WindowEvent e) {
                e.getWindow().repaint();
            }
        };

        window.addWindowFocusListener(windowFocusListener);

        return windowFocusListener;
    }
}

Related Tutorials