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

  • SEARCH
  • Home
  • 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 9126903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:09:35+00:00 2026-06-17T07:09:35+00:00

I have some Java Swing login panel. When user click login button, extensive DB

  • 0

I have some Java Swing login panel. When user click “login” button, extensive DB communication takes place. I got an idea to put that db communication into another thread (that db communication is used for filling some hash maps and singletons). After putting that communication into separate thread, db heavy lifting takes place while user is typing it’s uname and password. When user clicks “login” button, than code will wait for “heavy lifting” thread to join, and then proceed.

The problem is that while my code is waiting for db thread to join, it seems that no UI updates can be done. I don’t think i can use SwingWorker for db communication because user can click “login” button any time, even before SW would finish and i don’t have a way to join SwingWorker (db communication has to take place BEFORE actual login).

Is there a way to enable Swing ui updates while waiting for another thread to join? Am i missing something?

  • 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-17T07:09:36+00:00Added an answer on June 17, 2026 at 7:09 am

    Simply put two flags and at the end of both operations (DB-communication and user click), call the same method and verify there the state of the two flags. Possibly show a progress bar in a modal dialog if you want to block user input:

    import java.awt.BorderLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.SwingWorker;
    import javax.swing.UnsupportedLookAndFeelException;
    
    public class TestThreadJoin {
    
        private boolean dbWorkDone = false;
        private boolean credentialsProvided = false;
        private JTextField loginTF;
        private JTextField passwordTF;
    
        protected void initUI() {
            final JFrame frame = new JFrame(TestThreadJoin.class.getSimpleName());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel panel = new JPanel(new GridBagLayout());
            JLabel login = new JLabel("Login: ");
            JLabel password = new JLabel("Password: ");
            loginTF = new JTextField(20);
            passwordTF = new JPasswordField(20);
            GridBagConstraints gbc = new GridBagConstraints();
            panel.add(login, gbc);
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(loginTF, gbc);
            gbc.gridwidth = 1;
            panel.add(password, gbc);
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(passwordTF, gbc);
            JButton loginButton = new JButton("Login");
            loginButton.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    credentialsProvided = true;
                    proceed();
                }
            });
            frame.add(panel);
            frame.add(loginButton, BorderLayout.SOUTH);
            frame.pack();
            frame.setVisible(true);
            SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
    
                @Override
                protected Void doInBackground() throws Exception {
                    Thread.sleep(10000);
                    return null;
                }
    
                @Override
                protected void done() {
                    super.done();
                    dbWorkDone = true;
                    proceed();
                }
            };
            worker.execute();
        }
    
        protected void proceed() {
            if (credentialsProvided && dbWorkDone) {
                System.err.println("Continuing ");
            }
        }
    
        public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
                UnsupportedLookAndFeelException {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new TestThreadJoin().initUI();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a Java Swing newbie, I have some trouble separating the user interface logic
I am learning Java with Swing and I have some problems with using JTextField
I need to do some printing from my Java Swing application. I have tried
I have some java classes like, Class User { String email; String name; String
I have created a Java Swing application. Some users can't connect to the internet
I'm building an application using java.swing. I've got a main panel, a grid panel
I have an assignment to create a java Swing application to do some stuff
I have got a Java-Swing-GUI with a structure like this: JFrame -- JPanel1 -----jButton1
I have retail POS (Place of service) system implemented in .net and java swing
I have been doing some reading and have found out that the Java Swing

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.