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 resources
of 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.
Here is an outstanding example on using splash screens programmatically
The -splash is also described there.
Use java.awt.SplashScreen
class.
BTW I did not know that JVM has this cool options '-splash'. So, thanks for information!
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With