Swing Splashscreen

Hi,
I am a Java/Swing newbie, trying to convert from C++. I am writing a small app to interface with a PostgreSQL DB. I would like to include a splashscreen, and have used the code on sun's website (see below). I call this from the main().
The splashscreen loads however it is simply a grey box. I have no idea what is wrong with it? Anybody have any suggestions, much appreciated. Thanks!
////////////////////////////////////////// SPLASH SCREEN////////////////////////////////////////////
public class SplashScreen extends JWindow {
private int duration;
public SplashScreen(int d) {
duration = d;
// A simple little method to show a title screen in the center
// of the screen for the amount of time given in the constructor
public void showSplash() {
JPanel content = (JPanel)getContentPane();
content.setBackground(Color.BLUE);
// Set the window's bounds, centering the window
int width = 450;
int height =315;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
// Build the splash screen
JLabel label = new JLabel(new ImageIcon("/home/ehellaby/lehman.jpg"));
JLabel copyrt = new JLabel
("Lehman Brothers. Developed by Edward Hellaby", JLabel.CENTER);
copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
content.add(label, BorderLayout.CENTER);
content.add(copyrt, BorderLayout.SOUTH);
Color oraRed = new Color(156, 20, 20, 255);
content.setBorder(BorderFactory.createLineBorder(oraRed, 10));
// Display it
setVisible(true);
// Wait a little while, maybe while loading resources
try { Thread.sleep(duration); } catch (Exception e) {}
setVisible(false);
public void showSplashAndExit() {
showSplash();
System.exit(0);
}

OK, i think i got it.
If i take out the setVisible(false) the splash screen eventually loads up as it should once the rest of my app gets painted to the screen.
I have to find where to put the call to splash.showSplashScreen().
If you see below i have tried after setting my MDIForm as visible. But this never doesnt work.
Sorry if this seems daft, as i say i am a bit of a newbie to the graphics stuff!
Cheers
public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {              
                try{
                    new MDIScreen().setVisible(true);
                } catch(Exception e){}
                SplashScreen splash = new SplashScreen(1000);
                splash.showSplash();
    }

Similar Messages

  • ? SplashScreen - retrieving an image from a jar file ?

    When you want to use the Java SplashScreen you provide a run flag of the form:
    -splash:image.png
    Is there a way to have the 'image.png' reference a file in one of the jar files?I don't believe the jar files are loaded by the time SplashScreen activates so that might be why I can't seem to be able to do it, but that was when I checked over a year ago ... have things changed?
    Alternatively (and probably the preferred option for me) is there a way to tell the SplashScreen to create an empty splash so that one exists when I use the 'splash.setImageUrl()' method? Currently I have to set the splash image to be some empty/transparent image via:
    -splash:empty.png
    Then I set my own desired image via the 'splash.setImageUrl()' method...BUT, I still need to have the 'empty.png' file contained in the root folder of my project and this sucks. I'd like to be able to tell java that I want to create an empty splash, without having to provide an empty image, and then when the splash is created, I can use the image url method as normal to write my own image to the splash display.
    thx.

    morgalr, this is independent of code, it's just the splash screen that start up before any code runs so you could do this with any of your projects that you have.
    You need to specify splash image via run command of:
    -splash:image.png
    so, if you have a jar file that has an image in it, and you place it on your classpath and then try to run your code with
    -splash:package/path/image.png
    it doesn't seem to work...you'll know because either you'll see a splash screen or you won't. Note that the splash screen disappears the first time an AWT/Swing event is encountered (ie a frame is displayed, etc) so it may only last a few milliseconds but it still should come up. All of the links that discuss this talk about specifying a path to an images directory, but this images directory has to be in your project root folder and not in the source tree (as best as I can tell through experimentation).
    I guess what I would ultimately want would be to be able to create a SplashScreen instance through each program in my project without having to provide a runtime flag that only generates the instance if the provided image is available. If I it still provided a SplashScreen instance then I would be able to use the setImageUrl() method from code to provide the desired image. Also, it would be nice if the splashscreen remained some set time even after the application window popped up with an AWT/Swing event that now causes it to disappear instantly...but that one I can overcome with my own JWindow post-splash display that mimics the effect.
    thanks.

  • Help needed with splashscreen

    Hi ,
    I hava created a java application using swings. Now i am trying to create a executable jar file for the application. My question is i want to display a splashscreen while loading my application. I have gone through some tutorials and found that the code below is used to display splashscreen.
    Manifest-Version: 1.0
    Main-Class: Test
    SplashScreen-Image: filename.gif
    Can anyone tell me if the code below is enough or do i need to write a separate class file to display a splashscreen.
    Thankyou

    The code is enough if you are using Java 6 (still in the beta stages). The code should be included in your jar file manifest (I'm sure you know that)
    If you are using Java 5 or lower, you need to create a simple JWindow which contains the image you require and show this when the app starts, then hide the window just before or after calling setVisible(true) on you main application frame.
    Simple enough. Go grapple with it. There will be errors here and there. For comfort, you can look in your java demos under SwingSet2 and see if you can decifer how they created their splash screen
    Have Fun
    ICE

  • Manifest method for SplashScreen in Jave 6 not working?

    Okay I'm stumped.
    I am still not getting the splash screen to appear (it never shows up) using Java 6's new approach of putting the splash screen image name in the manifest file.
    Here is the entry from the manifest.mf file:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.0
    Created-By: 10.0-b19 (Sun Microsystems Inc.)
    Main-Class: ppo.PpoApp
    Class-Path: lib/appframework-1.0.3.jar lib/swing-worker-1.1.jar
    X-COMMENT: Main-Class will be added automatically by build
    SplashScreen-Image: splash.png
    I have also tried the following variations in place of "splash.png":
    splash.jpg
    splash.gif
    resources\splash.jpg
    resources\splash.gif
    resources\splash.png
    resources/splash.jpg
    resources/splash.gif
    resources/splash.png
    I have tried starting the app from the command line with the following:
    java -jar ppo.jar
    and by double clicking on the jar file (MS Windows XP SP2).
    I have tried starting the app from within the NetBeans IDE.
    There is no hint at all of the splashscreen.
    I am running JRE Java 6 update 4.
    Thanks in advance.
    Stu
    <previously posted with no response in Java Programming--maybe it is more appropriate here>

    Still working on it.....
    Here is the note I sent to the appframework mailing list a few minutes ago. Hopefully, I will get some ideas there.
    Certainly, I can go without the Application Framework, but I would still like to know what the issue is.
    More to follow....
    Stu
    Sent: Friday, February 08, 2008 10:11 PM
    To: '[email protected]'
    Subject: Splashscreen support?
    Okay, I�ve read the thread, but I have been testing various alternatives for several days now.
    And I know you said you have tested it, but if you have 5 minutes and you develop with NetBeans and the Java Application Framework, try this:
    Open NetBeans.
    Select New Project | Java | Java Desktop Application, press Next, then select Basic Application.
    Now without any other changes, just go into the manifest file and add the line for the splash screen. If you accept all the default names I think the line would be:
    SplashScreen-Image: desktopapplication1/resources/splash.png
    Then build and run it and see if the splash screen works.
    Mine doesn�t.
    If I put together an application without using the Java Desktop Application/Application Framework, I have no problems with the splash screen.
    Seems like a problem to me.
    Thanks
    Stu

  • Swing timers

    Currently having difficultly with swing timers and getting it to update it's delay
    We have a GUI app that will display screens for differing amounts of time, each screen has it's own time limit. The timer times out at 4000 for each screen( timerArray[0] );
    //I create the timer
    delay = timerArray[0];
    timer = new Timer( delay, this );
    //start the timer in the start buttons action performed.
    timer.start();
    //reset the timer in an inner class that repaints the JPanel
    delay = timerArray[currentScreen];
    timer.setDelay(delay);
    // stop and reset the screen in actionPerformed for main window
    System.out.println( currentScreen+" "+timer.getDelay() );
    contentPane.add( new splashScreen() );
    timer.stop();
    And the print out is
    1 4000
    2 20000
    3 60000
    4 15000
    So why is it not changing it's time?

    Are you sure you have understand that the Timer works like this :
    <---initialDelay--->fire ActionEvent<---delay--->fire ActionEvent<---delay--->fire Action Event<--- ...
    while it is not stopped.
    for example if you want the Timer to count 4 seconds you set the initial delay to 1000 (millis) and the delay to 1000 also.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SplashScreen extends JWindow {
         int duration = 0;
         int counter = 0;
         javax.swing.Timer timer;
         public SplashScreen() { 
              ImageIcon bg = new ImageIcon("image1.jpg");
              getContentPane().add(new JLabel(bg));
              pack();
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              setLocation(screenSize.width/2 - getWidth()/2,
                              screenSize.height/2 - getHeight()/2);
              timer = new javax.swing.Timer(1000, new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        counter++;
                        if (counter>=duration) {
                             closeSplashScreen();
         public void showSplashScreen(int seconds) {
              duration = seconds;
              counter = 0;
              setVisible(true);
              timer.start();
         public void closeSplashScreen() {
              if (timer.isRunning()) {
                   timer.stop();
              setVisible(false);
         public static void main(String[] args) {
              SplashScreen sp = new SplashScreen();
              sp.showSplashScreen(4);
    }------ unformatted version ----
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SplashScreen extends JWindow {
         int duration = 0;
         int counter = 0;
         javax.swing.Timer timer;
    public SplashScreen() { 
              ImageIcon bg = new ImageIcon("image1.jpg");
              getContentPane().add(new JLabel(bg));
              pack();
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              setLocation(screenSize.width/2 - getWidth()/2,
                             screenSize.height/2 - getHeight()/2);
              timer = new javax.swing.Timer(1000, new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        counter++;
                        if (counter>=duration) {
                             closeSplashScreen();
         public void showSplashScreen(int seconds) {
              duration = seconds;
              counter = 0;
              setVisible(true);
              timer.start();
         public void closeSplashScreen() {
              if (timer.isRunning()) {
                   timer.stop();
              setVisible(false);
         public static void main(String[] args) {
              SplashScreen sp = new SplashScreen();
              sp.showSplashScreen(4);
    Hope this helps,
    Denis

  • Splashscreen problem...

    Hi, I have a class that makes splash screen (found it somewhere online and then edited for my purpose). Now this only works at the beginning of a GUI application. In my specific program I need to make splash screens while the GUI is running. Here is the code for the splash screen class I used:
    // Splash Screen Class:
    class SplashScreen extends JWindow
        // Constructor for time:
        public int duration;
        public SplashScreen (int d)
            duration = d;
        // Splash Screen method:
        public void showSplash (BufferedImage source)
            // Initialization and background:
            JPanel content = (JPanel) getContentPane ();
            content.setBackground (Color.white);
            // Set the window's bounds, centering the window
            int width = source.getWidth ();
            int height = source.getHeight ();
            Dimension screen = Toolkit.getDefaultToolkit ().getScreenSize ();
            int x = (screen.width - width) / 2;
            int y = (screen.height - height) / 2;
            setBounds (x, y, width, height);
            // Build the splash screen
            JLabel image = new JLabel (new ImageIcon (source));
            content.add (image);
            content.setBorder (BorderFactory.createLineBorder (Color.black, 2));
            // Display it
            setLocation (8, 8);
            setVisible (true);
            // Wait a little while, maybe while loading resources
            try
                Thread.sleep (duration);
            catch (Exception e)
            setVisible (false);
        // Show splash screen for a while, then close:
        public void showSplashAndExit (BufferedImage source)
            showSplash (source);
    // To call the Splash Screen I use the following:
            try
                BufferedImage Introduction1 = ImageIO.read (new File ("IntroductionImages/Introduction1.jpg"));
                SplashScreen splash1 = new SplashScreen (2000);
                splash1.showSplashAndExit (Introduction1);
            catch (IOException e)
            }Anyways that works for the introduction only(while the GUI application is being loaded). But it does not work while the main frame is running. The only way I could do this is by using JinternalFrame. So basically, I want to make a similar splash screen class using JInternalFrame so that the splash screen will work WHILE the GUI application is running. If there is another way to do the above, I would highly appreciate your advice. If not, then can anybody tell me how I can manipulate this same class to be used for JInternalFrame. Any help would be greatly appreciated. Thanks!

    I see a problem with your potentially putting the EDT thread to sleep by calling Thread(sleep). Have you tried to use a Swing Timer instead?

  • Problem with threads in my swing application

    Hi,
    I have some problem in running my swing app. Thre problem is related to threads.
    What i am developing, is a gui framework where i can add different pluggable components to the framework.
    The framework is working fine, but when i press the close action then the gui should close down the present component which is active. The close action is of the framework and the component has the responsibility of checking if it's work is saved or not and hence to throw a message for saving the work, therefore, what i have done is that i call the close method for the component in a separate thread and from my main thread i call the join method for the component's thread.But after join the whole gui hangs.
    I think after the join method even the GUI thread , which is started for every gui, also waits for the component's thread to finish but the component thread can't finish because the gui thread is also waiting for the component to finish. This creates a deadlock situation.
    I dont know wht's happening it's purely my guess.
    One more thing. Why i am calling the component through a different thread, is because , if the component's work is not saved by the user then it must throw a message to save the work. If i continue this message throwing in my main thread only then the main thread doesnt wait for user press of the yes no or cancel button for saving the work . It immediately progresses to the next statement.
    Can anybody help me get out of this?
    Regards,
    amazing_java

    For my original bad thread version, I have rewritten it mimicking javax.swing.Timer
    implementation, reducing average CPU usage to 2 - 3%.
    Will you try this:
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    public class SamurayClockW{
      JFrame frame;
      Container con;
      ClockTextFieldW ctf;
      public SamurayClockW(){
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        con = frame.getContentPane();
        ctf = new ClockTextFieldW();
        con.add(ctf, BorderLayout.SOUTH);
        frame.setBounds(100, 100, 300, 300);
        frame.setVisible(true);
        ctf.start();
      public static void main(String[] args){
        new SamurayClockW();
    class ClockTextFieldW extends JTextField implements Runnable{
      String clock;
      boolean running;
      public ClockTextFieldW(){
        setEditable(false);
        setHorizontalAlignment(RIGHT);
      public synchronized void start(){
        running = true;
        Thread t = new Thread(this);
        t.start();
      public synchronized void stop(){
        running = false;
      public synchronized void run(){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try{
          while (running){
            clock = sdf.format(new Date());
            SwingUtilities.invokeLater(new Runnable(){
              public void run(){
                setText(clock);
            try{
              wait(1000);
            catch (InterruptedException ie){
              ie.printStackTrace();
        catch (ThreadDeath td){
          running = false;
    }

  • How to get the values from a html form embedded in a swing container

    Hi all,
    I am developing an application in which i have to read a html file and display it in a swing container.That task i made it with the help of a tool.But now i want to get the values from that page.ie when the submit button is clicked all the values of that form should be retrived by a servlet/standalone application.I don't know how to proceed further.Any help in this regard will be very greatful
    Thanks in advance,
    Prakash

    By parsing the HTML.

  • Is there free java chat, which i can embed in my Swing application

    Hello all,
    I have a Swing application and i want to embed java chat into it.
    Can you recommend me free chat for which i can see and modofy client and server sources.
    Regards,
    Chavdar

    No.

  • How to give Common Background color for all JPanels in My Swing application

    Hi All,
    I am developing a swing application using The Swing Application Framework(SAF)(JSR 296). I this application i have multiple JPanel's embedded in a JTabbedPane. In this way i have three JTabbedPane embedded in a JFrame.
    Now is there any way to set a common background color for the all the JPanel's available in the application??
    I have tried using UIManager.put("Panel.background",new Color.PINK);. But it did not work.
    Also let me know if SAF has some inbuilt method or way to do this.
    Your inputs are valuable.
    Thanks in Advance,
    Nishanth.C

    It is not the fault of NetBeans' GUI builder, JPanels are opaque by default, I mean whether you use Netbeans or not.Thank you!
    I stand corrected (which is short for +"I jumped red-eyed on my feet and rushed to create an SSCCE to demonstrate that JPanels are... mmm... oh well, they are opaque by default... ;-[]"+)
    NetBeans's definitely innocent then, and indeed using it would be an advantage (ctrl-click all JPanels in a form and edit the common opaque property to false) over manually coding
    To handle this it would be better idea to make a subclass of JPanel and override isOpaque() to return false. Then use this 'Trasparent Panel' for all the panels where ever transparency is required.I beg to differ. From a design standpoint, I'd find it terrible (in the pejorative sense of the word) to design a subclass to inconsistently override a getter whereas the standard API already exposes the property (both get and set) for what it's meant: specify whether the panel is opaque.
    Leveraging this subclass would mean changing all lines where a would-be-transparent JPanel is currently instantiated, and instantiate the subclass instead.
    If you're editing all such lines anyway, you might as well change the explicit new JPanel() for a call to a factory method createTransparentJPanel(); this latter could, at the programmer's discretion, implement transparency whichever way makes the programmer's life easier (subclass if he pleases, although that makes me shudder, or simply call thePanel.setOpaque(false) before returning the panel). That way the "transparency" code is centralized in a single easy to maintain location.
    I had to read the code for that latter's UI classes to find out the keys to use (+Panel.background+, Label.foreground, etc.), as I happened to not find this info in an authoritative document - I see that you seem to know thoses keys, may I ask you where you got them from?
    One of best utilities I got from this forum, written by camickr makes getting these keys and their values very easy. You can get it from his blog [(->link)|http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/]
    Definitely. I bit a pair of knucles off when discovered it monthes after cumbersomely traversing the BasicL&F code...
    Still, it is a matter-of-fact approach (and this time I don't mean that to sound pejorative), that works if you can test the result for a given JDK version and L&F, but doesn't guarantee that these keys are there to stand - an observation, but not a specification.
    Thanks TBM for highlighting this blog entry, that's the best keys list device I have found so far, but the questions still holds as to what specifies the keys.
    Edited by: jduprez on Feb 15, 2010 10:07 AM

  • How to get mouse wheel action in my swing application?

    Hi
    In my mouse, i am having mousewheel to support scrolling.With the help of the wheel, i can scroll the pages in IE browser or any other appliction.
    In swing application ,i have scroll bar inside a JFrame.I want to have mousewheel action in my swing application to support scrolling.
    any idea ???
    Thanks

    As far as I know,there is no facility for detecting mouse scrolling wheel in JDK 1.3.
    Check it in the later releases of JDK.

  • I want to implement thems functionality in  my swing application

    Hi All...
    I want to implement the themes object in my swing application,How ,where to start and move that functionality,If anybody use this functionality in your program experience can u share with me.
    Than to Advance
    ARjun...

    Hi Kuldeep Chitrakar
    I can do that in web intelligence. dont want that
    I am replicating some of the sample report of SQL Servers in BusinessObjects XI R3.1.
    One of the SQL Sever's report is of product catalogue type that gives complete information like name, category, description along with the products image etc... for each of the products.
    I am trying to replicate the above said SQL Server report in Business objects XI R3.1. I am facing problem in bringing the image in to my BO report. The image resides in a table and its datatype is of varbinary(max). I don't know the exact matching while creating an object in the uiverse designer.
    Here is the url link http://errorsbusinessobjectsxir3.blogspot.com/2010/10/business-objects-image-errors.html
    Regards
    Prasad

  • Can I build a GUI application with SWING only without [import java.awt.*;]

    I have seen several threads (in forums), books and tutorials about SWING and I see that they all mix SWING with AWT (I mean they import both Swing and AWT in their code).
    The conclusion that comes out is:
    It is good to learn about SWING and forget AWT as it won't be supported later. I have decided to do so, and I never include <<import java.awt.*;>> in my code.
    But I see that you cannot do much without <<import java.awt.*;>>. For example this line which changes the background color:
    <<frame.getContentPane().setBackground(Color.red)>>
    works only with <<import java.awt.*;>>. I have seen that codes in this and other forums import awt to change the background. Why is that?
    After all, I wonder, what can I do;
    My question is, can I change the background (and of course do all other things listener, buttons etc) without using <<import java.awt.*;>>.
    I would like to avoid using <<import java.awt.*;>> and using awt since my program will not work later.
    In addition, I believe there is no point to learn awt, which later will not exist.
    I know, I must have misunderstood something. I would appreceate it very much, if anyone could give me even a short answer.
    Thank you in advance,
    JMelsi

    Since swing is a layer on top of awt, AWT will exist for as long as swing does.
    If sun does ever remove AWT they will have to replace it something else swing can layer on to and you will probably only have to replace your import statements.
    The main difference is the way there drawn to the screen.
    You can do custom drawing on swing components but you can't on AWT.
    If your using a desktop PC system it's probably best to use swing just in case you wish to do some custom drawing.
    awt uses less memory than swing and is faster but swing can be extended. awt comes only as standard.
    Say for example you wish to implement a JButton with a ProgressBar below the button text, this can be done with swing!

  • Using the swing worker to populate the data in to jtablle

    Hello, i am developing my 1st application in java swings , i have developed it but when i run a module which fetchces the data from the mysql and display it in jtable my swing gui got blank for some initial time, i was thinking for some progress bar type thing but when i came acroos google i found that i can use swing worker to load my GUI on time and in the back ground i can do the task of fetching the data from the data base and populating the Jtable, but i had done a lot of try but not succeded to implement the swing worker . Please help me to implement the swing worker :( . i am using the abstractTableModal to populating the jtable it is working fine but swing worker is not there .
    Scenerio is like this i have base frame on which i got 1 or more btton one of those button is Clients when i click on it a Jdialog box appears with the jtable . Pleae tell me how to implement the swing worker class between this. Pleaseeeeeeeeeeeeeeeeeeeeee :( I am help less now .

    Fahim i want to display some photograph in to a swing application after fetching these photo graph from the database table , i dont know what swing component will be better for it and i m designing this in netbeans , so please assist me with that , how to go now and please note that it is dynamic so component should be like that :(. i m trying to create a photo album where i upload the multiple photograph first then i would like to show them each photograph will a text box when some one write some text in that text box and press enter i would like to save that text with that photo graph , I AM DONE WITH THE PHOTO UPLOADING TASK BUT DONT KNOW HOW TO DO THE REST LIKE DISPLAYING THE PHOTOGRAPH WITH THAT TEXT BOX .
    Edited by: kamal.java on Apr 27, 2012 8:59 AM

  • What is difference between C# Gzip and Java swing GZIPOutputStream?

    Hi All,
    I have a Java swing tool where i can compress file inputs and we have C# tool.
    I am using GZIPOutputStream to compress the stream .
    I found the difference between C# and Java Gzip compression while a compressing a file (temp.gif ) -
    After Compression of temp.gif file in C# - compressed file size increased
    while in java i found a 2% percentage of compression of data.
    Could you please tell me , can i achieve same output in Java as compared to C# using GZIPOutputStream ?
    Thank a lot in advance.

    797957 wrote:
    Does java provides a better compression than C#?no idea, i don't do c# programming. and, your question is most likely really: "does java default to a higher compression level than c#".
    Btw what is faster compression vs. better compression?meaning, does the code spend more time/effort trying to compress the data (slower but better compression) or less time/effort trying to compress the data (faster but worse compression). most compression algorithms allow you to control this tradeoff depending on whether you care more about cpu time or disk/memory space.

Maybe you are looking for