Here you can find the source of showLogo(ImageIcon logo)
Parameter | Description |
---|---|
logo | image icon for the logo |
public static JWindow showLogo(ImageIcon logo)
//package com.java2s; /** (C) Copyright 1998-2009 Hewlett-Packard Development Company, LP //from w w w.j a va2s . c o m This library 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 2.1 of the License, or (at your option) any later version. This library 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 this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JWindow; import javax.swing.border.SoftBevelBorder; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Rectangle; public class Main { /** * Shows the given Image as a logo on a simple window * * @param logo image icon for the logo * @return JWindow after setting the logo */ public static JWindow showLogo(ImageIcon logo) { JWindow logoWin = new JWindow(); JLabel jl = new JLabel(logo); JPanel jp = new JPanel(); jp.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED)); jp.add(jl); jp.setSize(jl.getPreferredSize()); logoWin.setContentPane(jp); logoWin.setSize(jp.getPreferredSize()); center(null, logoWin); logoWin.validate(); logoWin.toFront(); logoWin.setVisible(true); return logoWin; } /** * Centres a component inside an AWT container. <p> * If the container is null the component is centered in the * screen.</p> * * @param parent The AWT container * @param comp The component */ public static void center(Container parent, Component comp) { int x; int y; Rectangle parentBounds; Dimension compSize = comp.getSize(); // If Container is null or smaller than the component // then our bounding rectangle is the // whole screen if ((parent == null) || (parent.getBounds().width < compSize.width) || (parent.getBounds().height < compSize.height)) { parentBounds = new Rectangle(comp.getToolkit().getScreenSize()); parentBounds.setLocation(0, 0); } // Else our bounding rectangle is the Container else { parentBounds = parent.getBounds(); } // Place the component so its center is the same // as the center of the bounding rectangle x = parentBounds.x + (((parentBounds.width) - (compSize.width)) / 2); y = parentBounds.y + (((parentBounds.height) - (compSize.height)) / 2); comp.setLocation(x, y); } }