Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8233205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:03:20+00:00 2026-06-07T18:03:20+00:00

My main class loads configuration from a file then shows a frame. I want

  • 0

My main class loads configuration from a file then shows a frame. I want to make a splash screen with a progress bar like Eclipse so that the progress will increase while the file is being loaded and the splash disappears after the file is loaded. Then my main frame gets loaded.

MainClass code:

public static void main(String[] args) {
  ApplicationContext context = new ClassPathXmlApplicationContext(
    "classpath:/META-INF/spring/applicationContext.xml");
  // splash with progress load till this file is loaded
  UserDao userDao = context.getBean(UserDao.class);
  isRegistered = userDao.isRegistered();
  System.out.println("registered: " + isRegistered);
  if (isRegistered) {
    // progress finish and hide splash
    log.debug("user is registered"); // show frame1
  } else {
    // progress finish and hide splash
    log.debug("user is not registered"); // show frame2
  }
}

I don’t have much experience with Swing, so please advise how to accomplish that.

UPDATE: i have found the following example, but it have little issue:

  • when the counter gets to the specified number it should stop at (300) it keeps counting for ever without stopping the timer and hiding the splash screen.

  • i want to bind the counter to the file loading, so while the file is loaded the progress gets loaded until the file gets loaded then the progress completes and the splash screen disappears.

    @SuppressWarnings("serial")
    @Component
    public class SplashScreen extends JWindow {
    
        static boolean isRegistered;
    
        static Log log = LogFactory.getLog(SplashScreen.class);
    
        private static JProgressBar progressBar = new JProgressBar();
        private static SplashScreen execute;
        private static int count;
        private static Timer timer1;
    
        public SplashScreen() {
    
            Container container = getContentPane();
            container.setLayout(null);
    
            JPanel panel = new JPanel();
            panel.setBorder(new javax.swing.border.EtchedBorder());
            panel.setBackground(new Color(255, 255, 255));
            panel.setBounds(10, 10, 348, 150);
            panel.setLayout(null);
            container.add(panel);
    
            JLabel label = new JLabel("Hello World!");
            label.setFont(new Font("Verdana", Font.BOLD, 14));
            label.setBounds(85, 25, 280, 30);
            panel.add(label);
    
            progressBar.setMaximum(50);
            progressBar.setBounds(55, 180, 250, 15);
            container.add(progressBar);
            loadProgressBar();
            setSize(370, 215);
            setLocationRelativeTo(null);
            setVisible(true);
        }
    
        public void loadProgressBar() {
            ActionListener al = new ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    count++;
                    progressBar.setValue(count);
                    if (count == 300) {
                        timer1.stop();
                        execute.setVisible(false);
                        return;
                    }
                }
            };
            timer1 = new Timer(50, al);
            timer1.start();
        }
    
        public static void main(String[] args) {
    
            execute = new SplashScreen();
    
            ApplicationContext context = new ClassPathXmlApplicationContext(
                    "classpath:/META-INF/spring/applicationContext.xml");
    
            UserDao userDao = context.getBean(UserDao.class);
    
            isRegistered = userDao.isRegistered();
    
    
            if (isRegistered) {
                 // show frame 1
            } else {
                                                        // show frame 2
    
            }
    
        }
    
    }
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:03:22+00:00Added an answer on June 7, 2026 at 6:03 pm

    when the counter gets to the specified number it should stop at (300)
    it keeps counting for ever without stopping the timer and hiding the
    splash screen.

    The code below seems to work great (with the fatal flaw the counter may take longer then the file loading and vice versa):

    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.HeadlessException;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    public class SplashScreen extends JWindow {
    
        static boolean isRegistered;
        private static JProgressBar progressBar = new JProgressBar();
        private static SplashScreen execute;
        private static int count;
        private static Timer timer1;
    
        public SplashScreen() {
    
            Container container = getContentPane();
            container.setLayout(null);
    
            JPanel panel = new JPanel();
            panel.setBorder(new javax.swing.border.EtchedBorder());
            panel.setBackground(new Color(255, 255, 255));
            panel.setBounds(10, 10, 348, 150);
            panel.setLayout(null);
            container.add(panel);
    
            JLabel label = new JLabel("Hello World!");
            label.setFont(new Font("Verdana", Font.BOLD, 14));
            label.setBounds(85, 25, 280, 30);
            panel.add(label);
    
            progressBar.setMaximum(50);
            progressBar.setBounds(55, 180, 250, 15);
            container.add(progressBar);
            loadProgressBar();
            setSize(370, 215);
            setLocationRelativeTo(null);
            setVisible(true);
        }
    
        private void loadProgressBar() {
            ActionListener al = new ActionListener() {
    
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    count++;
    
                    progressBar.setValue(count);
    
                    System.out.println(count);
    
                    if (count == 300) {
    
                        createFrame();
    
                        execute.setVisible(false);//swapped this around with timer1.stop()
    
                        timer1.stop();
                    }
    
                }
    
                private void createFrame() throws HeadlessException {
                    JFrame frame = new JFrame();
                    frame.setSize(500, 500);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setVisible(true);
                }
            };
            timer1 = new Timer(50, al);
            timer1.start();
        }
    
        public static void main(String[] args) {
            execute = new SplashScreen();
        }
    };
    

    i want to bind the counter to the file loading, so while the file is
    loaded the progress gets loaded until the file gets loaded then the
    progress completes and the splash screen disappears.

    You should take a look at ProgressMonitor and ProgressMonitorInputStream using a Task you may then check when the file is completely read and end the SplashScreen. see here for some great tutorial and explanation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main conf file which I load using apache common configuration class.
I want to have some custom configuration (read in from file) available throughout my
I have a main class(which is basically a netbeans form;drag and drop) from where
I subclassed UIScrollView Then created an object of it in the main class. Added
In a Grails 1.1 plugin, I'm trying to load a class from the main
My ASP.NET application loads an assembly and creates a class instance from an object
I have a main class in a program that launches another class that handles
// Here's my code: Main Class: import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.BufferStrategy;
I have a Main class and a HelloWorld class. I have created a button
I have a Class(call it main class) and the method in main class calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.