HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Working with Swing"
Vol. 5, Issue 10, p. 108


Listing 1

public void createSplashScreen()
  // Create a JLabel for the title. Ensure that the text is   
  // centered within the JLabel and that the JLabel is cen-
  // tered within the window.
  JLabel _title = new JLabel("SplashScreen Test v3.1", JLa- 

  // Set the color of the text in the title. The background    
  // will be that of the window itself.

  // ditto for the progress indicator
  progressLabel = new JLabel("Connecting to server...", JLa-   

  // Create the SplashScreen
  splashScreen = new SplashScreen(
    this, "net/jools/test/SplashTest.jpg", _title, progressLabel);

  // Set the background color of the SplashScreen

  // Show the SplashScreen

Listing 2

public SplashScreen(...)
  JComponent pane = (JComponent)getContentPane();

  // Use a vertical BoxLayout to arrange the components
  // top to bottom.
  pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

  i = new ResourceImageIcon(splashName);

  // To ensure that the image is centered horizontally, cen-
  // ter it in the JLabel and center the JLabel in the window.
  image = new JLabel(i, JLabel.CENTER);

  // Add a border to the window

  // The order in which the components are now added to the
  // window is important. First the title, then the image,
  // then the footer.

  // To ensure that the title component spans the full width 
  // of the window set its maximum sizes. The caller is 
  // responsible for its alignment
  if (title != null) {
      new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));


  if (footer != null) {
      new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.