Custom Made SplashScreen class unusual behaviour.

Posted on 2007-09-30
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?
Question by:prain
    LVL 8

    Expert Comment

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

      public static void main(String[] args) {

         SplashScreen splash = new SplashScreen(5000);

        PopSplash frame1 = new PopSplash();


    Author Comment

    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.

    Author Comment

    OK. I have solved the problem. I had to incorporate a timer instead of delaying by using Thread.sleep().
    LVL 1

    Accepted Solution

    PAQed with points refunded (125)

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now