Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show SplashScreen Programmatically

I'm currently working on a Java Application and it's my first Java App. So I created a file Splash.png and placed it into the source folder resourcesof the application.

I already managed it to show the Splash image on startup, with the JVM param -splash:resources/Splash.png, but my question is;

How can I show this splash screen again, but programmatically?

I need this functionality for the About menu item.

like image 834
evotopid Avatar asked Nov 20 '11 19:11

evotopid


3 Answers

Here is an outstanding example on using splash screens programmatically

The -splash is also described there.

like image 94
GETah Avatar answered Sep 19 '22 17:09

GETah


Use java.awt.SplashScreen class.

BTW I did not know that JVM has this cool options '-splash'. So, thanks for information!

like image 26
AlexR Avatar answered Sep 20 '22 17:09

AlexR


Thanks for your great help. I thought there isn't really any function which does this, so I just coded a JFrame, which I can show instead of the Splash screen on launch. For the case that someone could need the code also I just post it here:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class AboutWindow extends JFrame implements MouseListener {

    public AboutWindow() {
        // show splash screen image
        ImageIcon icon = new ImageIcon("resources/Splash.png");
        JLabel label = new JLabel(icon);
        getContentPane().add(label, BorderLayout.CENTER);

        // setup window correct
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setUndecorated(true);

        pack();

        // place it at the right position
        Dimension windowDimension = Toolkit.getDefaultToolkit().getScreenSize();

        int x = (windowDimension.width-getWidth())/2;
        int y = (windowDimension.height-getHeight())/3;

        setLocation(x, y);

        // add the mouse listener
        addMouseListener(this);
    }

    @Override
    public void mouseClicked(MouseEvent me) {
        dispose();
    }

    @Override
    public void mousePressed(MouseEvent me) {
        // do nothing
    }

    @Override
    public void mouseReleased(MouseEvent me) {
        // do nothing
    }

    @Override
    public void mouseEntered(MouseEvent me) {
        // do nothing
    }

    @Override
    public void mouseExited(MouseEvent me) {
        // do nothing
    }
}
like image 2
evotopid Avatar answered Sep 20 '22 17:09

evotopid