• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ImageIcon and JLabel together

 
Kevin Goodwin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic