Example usage for javax.swing JWindow getWidth

List of usage examples for javax.swing JWindow getWidth

Introduction

In this page you can find the example usage for javax.swing JWindow getWidth.

Prototype

public int getWidth() 

Source Link

Document

Returns the current width of this component.

Usage

From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java

/**
 * Called via SingleInstanceListener / SingleInstanceService. Shows a
 * splashscreen and bring the existing instance to the front.
 *///from  w  ww . j  a  v a2s  . c  om
@Override
public void newActivation(String[] arg0) {
    LOGGER.info(
            "A second instance of AtlasViewer has been started.. The single instance if requesting focus now...");

    /*
     * Showing the Spalshscreen for one secong
     */
    try {
        final URL splashscreenUrl = atlasConfig.getResource(AtlasConfig.SPLASHSCREEN_RESOURCE_NAME);
        if (splashscreenUrl != null) {
            JWindow splashWindow = new JWindow(atlasJFrame);
            JPanel panel = new JPanel(new BorderLayout());
            ImageIcon icon = new ImageIcon(splashscreenUrl);
            panel.add(new JLabel(icon), BorderLayout.CENTER);
            panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            splashWindow.getContentPane().add(panel);
            splashWindow.getRootPane().setOpaque(true);
            splashWindow.pack();
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            splashWindow.setLocation((int) (d.getWidth() - splashWindow.getWidth()) / 2,
                    (int) (d.getHeight() - splashWindow.getHeight()) / 2);
            splashWindow.setVisible(true);
            Thread.sleep(1500);
            splashWindow.dispose();
            splashWindow = null;
        }
    } catch (Exception e) {
        LOGGER.warn("Singleinstance.newActivation had problems while showing the splashscreen:", e);
    }

    if (getJFrame() != null) {
        if (!getJFrame().isShowing())
            getJFrame().setVisible(true);

        /* In case that it has been iconified */
        getJFrame().setExtendedState(Frame.NORMAL);

        getJFrame().requestFocus();
        getJFrame().toFront();
    }
}