aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ImageIcon and JLabel together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ImageIcon and JLabel together" Watch "ImageIcon and JLabel together" New topic
Author

ImageIcon and JLabel together

Kevin Goodwin
Greenhorn

Joined: May 16, 2005
Posts: 6
I'm now having a problem with a simple splash screen that I have to make. I have the Java icon as a .gif image in my local directory and I am calling it into a JWindow that is set up as the splash screen using Graphics mode (a requirement).
The problem is that either the Java icon shows up or the Graphic text does, but not both. Why? I would appreciate some help on understanding this. Thank you.

My code follows:

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

public class ProTrackSplash extends JWindow {

public ProTrackSplash() {
setSize(600, 400);
setLocation(200, 200);

TrackSplashPane ts = new TrackSplashPane();
ImageIcon javalogo = new ImageIcon("javalogo52x88.gif");
JLabel label = new JLabel(javalogo);

Container content = getContentPane();
content.add(ts);
content.add(label);

setVisible(true);
}
class TrackSplashPane extends JPanel {

public void paintComponent(Graphics comp) {
Graphics comp2D = (Graphics2D)comp;
Font f = new Font("Monospaced", Font.BOLD, 24);
FontMetrics fm = getFontMetrics(f);
comp2D.setFont(f);

String a = "Project and Time Tracker";
comp2D.drawString(a,120,160);

String b = "By: Kevin Goodwin";
comp2D.drawString(b,155,230);
}
}
public static void main (String args[]) {
ProTrackSplash frame = new ProTrackSplash();

try {
Thread.sleep(2000);
System.exit(0);
} catch (InterruptedException ie) { }
}
}
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The default layout manager for JWindow is BorderLayout. When you add a component to a BorderLayout with no constraint, eg, "East" or BorderLayout.NORTH, it is added to the center section by default. When you add the splash screen to the center and then add the JLabel to the center the spalsh screen is removed and the JLabel is placed in the center. You could add the JLabel to the north or south sections. See the BorderLayout api for details.

[ May 18, 2005: Message edited by: Craig Wood ]
Kevin Goodwin
Greenhorn

Joined: May 16, 2005
Posts: 6
Thank you for the reminder and code example. I made one north and the other center and things are fine now. I knew it would be something simple...sheesh I don't know if I'll ever learn this stuff.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ImageIcon and JLabel together