Results 1 to 10 of 10
  1. #1
    ggyyree is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Question How to put a splash screen in front of the main UI?

    Hi guys,

    I am a newbie of this forum, and I've got a problem want to discuss with you.

    How to put a splash screen in front of the main UI? My requirement is displaying a splash screen before the main UI is ready (maybe loading something at the backend). Moreover, I need the splash screen displays on top of the main UI, but all the components in the main UI should be gray out.

    I wrote some codes (partially as following), but it seems didn't work like I expected.

    Thanks very much.

    Java Code:
    public class testGUI
    {
    
        public static void main(String args[])
        {
    
            testGUISplash splash = new testGUISplash(5000);
            // splash.setAlwaysOnTop(true);
            splash.showSplash();
    
            java.awt.EventQueue.invokeLater(new Runnable()
            {
                public void run() {
                    testGUIView view = new testGUIView();
                    // view.setAlwaysOnTop(true);
                    view.setVisible(true);   
                }
            }
            );
    
        }
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    ggyyree is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    If you're using Java 1.6, you can do it via the SplashScreen class:

    SplashScreen API
    SplashScreen Tutorial
    Thanks for your fast replying.

    Actually, I've read that example before; however, it didn't work quite well with my application, and it is quite complicated. My splash screen contains only one image file, and my question is not about how to create a splash screen.

    Currently, my thought is how to show two windows(or frames) at the same time. One is my main UI, and one is my splash screen. One is on top, and one is at back with all the buttons, menus disabled.

    May I ask if there is a good example about this please? Thanks.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by ggyyree View Post
    Actually, I've read that example before; however, it didn't work quite well with my application, and it is quite complicated.
    How didn't it work for you? It seems to me to be easier to do it this way than to do what you mention below.

    My splash screen contains only one image file, and my question is not about how to create a splash screen.
    ? Your thread title confuses me then.


    Currently, my thought is how to show two windows(or frames) at the same time. One is my main UI, and one is my splash screen. One is on top, and one is at back with all the buttons, menus disabled.

    May I ask if there is a good example about this please? Thanks.
    I suppose you could create this yourself using an undecorated JDialog, but then you'll have to write all the code for this yourself, and again, a SplashScreen would likely be easier.

    Best of luck.
    Last edited by Fubarable; 11-26-2010 at 09:33 PM.

  5. #5
    ggyyree is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Default

    Sorry. Mate. I should make my question clear.

    1. How to show the splash screen and the main UI at the same time?

    2. Before the splash screen fade, how to make all the components on the main UI gray out?

    I look at the SplashScreen API but I don't know which method I can use to implement my idea.

    Currently I write my testGUISplash class derived from JWindow, which contains one image only. But I really have no clue to carry on.

    Any idea would be appreciate. Thanks.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by ggyyree View Post
    Sorry. Mate. I should make my question clear.

    1. How to show the splash screen and the main UI at the same time?
    You display your splash window as a separate top-level component, be it a JWindow, a JDialog, or whatever you desire.


    2. Before the splash screen fade, how to make all the components on the main UI gray out?
    I know of no single simple way to do this since as you've probably found out, calling setEnabled(false) on your JFrame does disable it, but it doesn't gray out the components.. If I've had to gray out all the components in a container or a GUI, I've sometimes used a method that recursively goes through all the components held by a container and calls setEnabled(false) on them, and then visa versa to re-enable. There is some danger doing this as you can re-enable components that you don't want enabled for other reasons.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    For example:

    Java Code:
       public static void setEnabledAll(Container container, boolean enabled) {
          Component[] components = container.getComponents();
          if (components.length > 0) {
             for (Component component : components) {
                component.setEnabled(enabled);
                if (component instanceof Container) {
                   setEnabledAll((Container)component, enabled); // the recursive call
                }
             }
          }
       }

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    how to make all the components on the main UI gray out?
    This blog post by camickr may be useful
    Disabled Panel « Java Tips Weblog

    db

  9. #9
    ggyyree is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Thumbs up

    Hi guys,

    Thanks a looooooooooooooooot!!!!!! :)

    Currently, I've got another problem, which is quite confused me.

    As my

    Java Code:
    public class testGUISplash extends JWindow
    {
    
        /** Define member variables */
        private int threadWaitingDuration;
    
        /** Constructor */
        /** @param durationTime The splash screen showing time */
        public testGUISplash(int durationTime) {
            threadWaitingDuration = durationTime;
        }
    
        public void showSplash() {
            // Put an image here
            JLabel label = new JLabel(new ImageIcon("src/res/SplashScreenSmall.PNG"));
    
            // And other codes
        }
    }
    If I do this:

    Java Code:
    public class testGUI
    {
    
        public static void main(String args[])
        {
    
            testGUISplash splash = new testGUISplash(5000);
            splash.setAlwaysOnTop(true);
            splash.showSplash();
    
            java.awt.EventQueue.invokeLater(new Runnable()
            {
                public void run() {
                    testGUIView view = new testGUIView();
                    // view.setAlwaysOnTop(true);
                    view.setVisible(true);   
                }
            }
            );
    
        }
    
    }
    We can't show the splash window and main UI at the same time; however, if I do:

    Java Code:
    public class testGUI
    {
    
        public static void main(String args[])
        {
    
            testGUISplash splash = new testGUISplash(5000);
            splash.setAlwaysOnTop(true);
    
            testGUIView view = new testGUIView();
            view.setVisible(true);   
              
            splash.showSplash();
        }
    
    }
    I can show them at the same time. (My requirement one.)

    I am wondering what java.awt.EventQueue.invokeLater do exactly? I read some text books, and they said Swing has only one single thread called the event dispatch thread. I guess it is this one java.awt.EventQueue.invokeLater, but do we need it and why do we need it?

    Could anyone specify some more details please?

    Thanks very much!

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Could anyone specify some more details please?
    I don't think anyone here can explain it better than the tutorial:
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db

Similar Threads

  1. Splash Screen How?
    By bircastri in forum AWT / Swing
    Replies: 1
    Last Post: 11-16-2010, 04:51 PM
  2. Splash Screen
    By madcommu in forum SWT / JFace
    Replies: 4
    Last Post: 09-18-2010, 01:14 PM
  3. splash screen
    By joypik in forum AWT / Swing
    Replies: 1
    Last Post: 07-13-2010, 07:48 PM
  4. Splash screen on my project
    By ibrahimyoussof in forum New To Java
    Replies: 1
    Last Post: 04-14-2010, 03:17 PM
  5. Splash Screen
    By Doctor Cactus in forum New To Java
    Replies: 1
    Last Post: 10-29-2008, 06:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •