the code below is the implementation of a splash screen for a small Java application I have developed with Eclipse. The splash screen works perfectly well on a PC but not on a MAC. On MAC OSX, the frame first appears has a gray area during 2 seconds and then the image appears for the remaining of the 4 seconds. The image should normally appears right away and for a duration of 4 seconds. Do you have any idea why there is a delay before the image appears on a MAC while everything works well on a PC? PS: I have deployed the application as an executable Jar and I'm using Java 8 on all computers. Thank you.
public static void main(String[] args)
{
SplashScreen splSplashScreen = new SplashScreen();
//Main window
FenetrePrincipale fenetrePrincipale = new FenetrePrincipale();
}
public class SplashScreen extends JWindow
{
/**
* Numéro de série
*/
private static final long serialVersionUID = 1592663893301307318L;
private final static long TEMP_AFFICHAGE = 4000;
/**
* Constructeur par initialisation
* @param p_Frame Frame
* @param p_TempsAffichage Temps d'affichage en millisecondes
*/
public SplashScreen()
{
super(new Frame());
JLabel lblImage = new JLabel(new ImageIcon(this.getClass().getResource("/res/ui/splashScreen.jpg")));
Container container = this.getContentPane();
container.add(lblImage, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = lblImage.getPreferredSize();
this.setLocation(screenSize.width/2 - (labelSize.width/2), screenSize.height/2 - (labelSize.height/2));
this.setVisible(true);
try
{
Thread.sleep(TEMP_AFFICHAGE);
}
catch (InterruptedException ex)
{
ApplicationLogger.getInstance().severe(ex.getLocalizedMessage());
}
finally
{
this.setVisible(false);
}
}
}