Java ImageIcon showLogoProgressBar(ImageIcon logo, int steps)

Here you can find the source of showLogoProgressBar(ImageIcon logo, int steps)

Description

Shows progress bar with logo

License

Open Source License

Parameter

Parameter Description
logo logo
steps steps

Return

JProgressBar object with logo

Declaration

public static JProgressBar showLogoProgressBar(ImageIcon logo, int steps) 

Method Source Code

//package com.java2s;
/** (C) Copyright 1998-2009 Hewlett-Packard Development Company, LP
    /*from ww  w . j  av a  2  s. c om*/
 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.JProgressBar;
import javax.swing.JWindow;
import javax.swing.border.SoftBevelBorder;

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

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import java.awt.Rectangle;

public class Main {
    /**
     * Shows progress bar with logo
     *
     * @param logo  logo
     * @param steps steps
     * @return JProgressBar object with logo
     */
    public static JProgressBar showLogoProgressBar(ImageIcon logo, int steps) {
        JProgressBar jpb = new JProgressBar();
        jpb.setMinimum(0);
        jpb.setMaximum(steps);

        JWindow pBarWin = new JWindow();
        JLabel jl = new JLabel(logo);
        JPanel jp = new JPanel();
        jp.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));

        GridBagLayout layout = new GridBagLayout();
        jp.setLayout(layout);

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.fill = GridBagConstraints.BOTH;
        constraints.weightx = 2.0;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        layout.setConstraints(jl, constraints);
        jp.add(jl);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        layout.setConstraints(jpb, constraints);
        jp.add(jpb);
        jp.setSize(jl.getPreferredSize());
        pBarWin.setContentPane(jp);
        pBarWin.setSize(jp.getPreferredSize());
        center(null, pBarWin);
        pBarWin.validate();
        pBarWin.toFront();
        pBarWin.setVisible(true);

        return jpb;
    }

    /**
     * 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);
    }
}

Related

  1. setImageIcon(ImageIcon icon, String description)
  2. setImageIcon(JLabel label, URL url)
  3. SetStandardSizeForImage(ImageIcon icon)
  4. setVerBumpIcon(ImageIcon icon)
  5. showLogo(ImageIcon logo)
  6. showSplash(ImageIcon image, int milliseconds)
  7. showSplash(ImageIcon image, int milliseconds)
  8. toDisabledIcon(ImageIcon icon)
  9. toImagesList(final List imageIcons)