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- 
                            bel.CENTER);
  _title.setAlignmentX(Component.CENTER_ALIGNMENT);

  // Set the color of the text in the title. The background    
  // will be that of the window itself.
  _title.setForeground(Color.green);

  // ditto for the progress indicator
  progressLabel = new JLabel("Connecting to server...", JLa-   
                            bel.CENTER);
  progressLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  progressLabel.setForeground(Color.green);

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

  // Set the background color of the SplashScreen
  splashScreen.getContentPane().setBackground(Color.white);

  // Show the SplashScreen
  splashScreen.setVisible(true);
}

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);
  image.setAlignmentX(Component.CENTER_ALIGNMENT);

  // Add a border to the window
  pane.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createRaisedBevelBorder(),
    BorderFactory.createLoweredBevelBorder()));

  // 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) {
    title.setMaximumSize(
      new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
      pane.add(title);
  }

  pane.add(image);

  if (footer != null) {
    footer.setMaximumSize(
      new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    pane.add(footer);
 }
  ...
}
  
 
 

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.