Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Putting variable text over a splash screen

 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
--Mark
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic