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 Putting variable text over a splash screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Putting variable text over a splash screen" Watch "Putting variable text over a splash screen" New topic

Putting variable text over a splash screen

Mark Herschberg

Joined: Dec 04, 2000
Posts: 6037
I am using a splash screen at the start of my program:

It is simply a small image with the name of the software. I want to include a variable tagline underneath the software logo (e.g. an image of the windows logo with text below reading "Crushing competition since 1983" or something like that). This tag line will be randomly selected at runtime. I would prefer not to have to generate multiple images, since that will take up a lot of memory. How can I do this?
Can I overlay a transparent slpash screen with the text? Can I add text to the image dynamically? Can I embed the image in a headless window and overlay a glass pane with text? Any other ideas?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I think what you can do is override the paintComponent method of your Window or Panel (depending on where you want your image). Then, when you add your JLabel it will display on top of your image. And you can dynamically choose your JLabel text at runtime if you wish.

Something like that for the overridden painComponent method. Where yourImage is an Image object. Hope that helps.

GenRocket - Experts at Building Test Data
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121


This depends on the JCSplashScreen class... is this your class, do you have the source, can you extend it? If any of these are the case, either modify or extend the class to allow you to set a String and also modify the paintComponent() method to draw a string over the image using the drawString() method of Graphics.

Even if you don't have the code to the class, and can't override it, you can make a BufferedImage of your image and draw the string on that, then send the buffered image to the splash screen class.

If you need any help on either of these approaches, just post your questions!

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Putting variable text over a splash screen
jQuery in Action, 3rd edition