We help IT Professionals succeed at work.

Custom Made SplashScreen class unusual behaviour.

prain asked
Last Modified: 2013-12-29
I have a terrible problem....

I am really working on Java 1.5. So I cannot use the SplashScreen class given in java 1.6. Therefore I picked up a SplashScreen class written by some on the net and tailored it. I run the SpalshScreen INDEPENDENTLY. That works great.

Then I created a separate JFrame and at the close of the frame (at the click of the X button at the Top RHS corner), I I am triggering the WindowClosing event and sopposed to see the SpalshScreen pops up. But this is how it behaves ....

1. In Java 1.5 - Only a white background displays and after the time out it goes away.

2. In Java 1.6 nothing is displayed, but at the timeout the main window who invokes the Spash exits.

My question is....
WHY IS THAT THE INDEPENDENT SplashScreen works and when Attached it behaves weiredly.

Here is the code of SplashScreen. Just compile and run this. Then I have the small window I have created to trigger the SplashScreen. That also in here for you to test out.

import java.awt.*;
import javax.swing.*;

public class SplashScreen extends JWindow {
  private int duration;
  public SplashScreen(int d) {
    duration = d;

  // A simple little method to show a title screen in the center
  // of the screen for the amount of time given in the constructor
  public void showSplash() {
    JPanel content = (JPanel)getContentPane();

    // Set the window's bounds, centering the window
    int width = 450;
    int height =115;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width-width)/2;
    int y = (screen.height-height)/2;

    // Build the splash screen
    JLabel label1 = new JLabel("Shutting down.....", JLabel.CENTER);
    label1.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    content.add(label1, BorderLayout.NORTH);
    JPanel messagePanel = new JPanel(new GridLayout(2, 1));
    messagePanel.setPreferredSize(new Dimension(100, 30));
    JLabel label2 = new JLabel ("Closing Connection at port xxxx...", JLabel.CENTER);
    label2.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    messagePanel.add(label2, BorderLayout.SOUTH);
    JLabel label3 = new JLabel ("Closing Connection at port yyyy...", JLabel.CENTER);
    label3.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    messagePanel.add(label3, BorderLayout.SOUTH);
    content.add(messagePanel, BorderLayout.CENTER);
    JLabel label4 = new JLabel ("xxxxxxxxxx Version 1.0", JLabel.CENTER);
    label4.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    content.add(label4, BorderLayout.SOUTH);
    Color oraRed = new Color(156, 20, 20,  255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 10));

    // Display it

    // Wait a little while, maybe while loading resources
    try { Thread.sleep(duration); } catch (Exception e) {}


  public void showSplashAndExit() {

  public static void main(String[] args) {
    // Throw a nice little title page up on the screen first
    SplashScreen splash = new SplashScreen(5000);
    // Normally, we'd call splash.showSplash() and get on with the program.
    // But, since this is only a test...

================================= HERE IS THE TRIGGER CLASS==========
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PopSplash extends JFrame implements ActionListener
       JButton splashButton;
  public PopSplash()
    FlowLayout layout = new FlowLayout();
    this.setTitle("Window 1");
    this.setSize(335, 150);
    this.setLocation(200, 100);

    splashButton = new JButton("Splash");
    splashButton.setPreferredSize(new Dimension(95,30));
  public void actionPerformed(ActionEvent aEvent)
   if(aEvent.getSource() == splashButton)

 WindowListener windowClosingListener = new WindowAdapter()
      // anonymous WindowAdapter class
    public void windowClosing(WindowEvent w)
     SplashScreen splash = new SplashScreen(5000);
     } // end windowClosing
   };// end anonymous class

  public static void main(String[] args) {
    PopSplash frame1 = new PopSplash();

Can some one throw some light to this?
Watch Question

 public void showSplashAndExit() {
    System.exit(0);     //<- remove

  public static void main(String[] args) {

     SplashScreen splash = new SplashScreen(5000);

    PopSplash frame1 = new PopSplash();



Well I am not using this Splash as a start up. I am using this as a End Spash that will show the end of the program after the user decides to close the program. In the SpashScreen I am showing up some network disconnecting messages etc. To end the program, user will either select the "Exit" menut item or will click the Std. 'X' window closing icon at teh top RHS of the window. Then I am suposed to see this splash. That's why I have put that in the windowClosing() in my given example.


OK. I have solved the problem. I had to incorporate a timer instead of delaying by using Thread.sleep().
Unlock this solution and get a sample of our free trial.
(No credit card required)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.