File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

ImageIcon and JLabel together

Kevin Goodwin

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();

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);

String a = "Project and Time Tracker";

String b = "By: Kevin Goodwin";
public static void main (String args[]) {
ProTrackSplash frame = new ProTrackSplash();

try {
} 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

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:
subject: ImageIcon and JLabel together
It's not a secret anymore!