JProgress bar that pops up

How would I go about putting a JProgressBar right in the middle of my application when a button is clicked, that doesn't allow you to access the actual application below until the process is done?
LVL 2
k41d3nAsked:
Who is Participating?
 
CEHJCommented:
Modal JDialog - put a JProgressBar on it
0
 
zzynxSoftware engineerCommented:
0
 
k41d3nAuthor Commented:
CEHJ,

I made a JDialog and put a progress bar in it
I also set Modal to true on jDialog


I call the jDialog when I press a button, the popup pops up in the upper left corner of the app and disables accessing below it, which is good. However, it stops processing the other action of my button click until I hit the "X" on the jDialog.

Ideally, it should popup the progress bar, and still run the tests, what am I doing wrong here?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CEHJCommented:
>>However, it stops processing the other action of my button click

Is the 'other action' started before or after you show the JDialog and what is it btw?
0
 
CEHJCommented:
Sorry that question's a bit wrong, since it can't start after until you close the JDialog. What i'm getting at is - can you tell me the sequence of events and what's happening?
0
 
k41d3nAuthor Commented:
Sure!

I have a button, and I have an actionlistener on that button. When I click the button, I popup the JDialog, and run the tests:

    /**
     * This method initializes runSelectedTestsButton
     *
     * @return javax.swing.JButton
     */
    private JButton getRunSelectedTestsButton() {
        if (runSelectedTests == null) {
            runSelectedTests = new JButton();
            runSelectedTests.setText("Run Selected");
            runSelectedTests.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    Runnable processor = new Runnable() {
                        public void run() {
                            try {
                                JDialog prog = getPopupBar();
                                prog.setVisible(true);
                                TestRecords tr = new TestRecords();
                                tr.setType(TestRecords.SELECT);
                                tr.initialize();
                                tr.createResults();
                                TestAction test = new TestAction();
                                tr.createSummary(getChildTab(getParentTabIndex()), getParentTab());        
                                List allSelected = getSelectedCheckBoxes();
                                int status = allSelected.size();
                                for (Iterator it = allSelected .iterator(); it.hasNext(); ) {
                                    Object element = it.next();
                                    String testName = element.toString();
                                    progress.setString("Running: " + testName);
                                    System.out.println("Running: " + testName);
                                    test.runTest(tr, testName);                                  
                                }
                                //Log and display results
                                AllHttpTests.displayResults(tr.getResults(), tr.getSummary());
                                progress.setString("Getting Results");
                                //Add the result of the test to the summary
                                TestRecords.getResultHash(tr.getSummary());
                                tr.closeSession(tr.getSession(), tr.getSummary());
                                prog.setVisible(false);
                            } catch (Exception e) {
                                atelog.error(e);
                                e.printStackTrace();
                            }
                        }
                    };
                    begin = new Thread(processor);
                    begin.start();
                }
            });
        }
        return runSelectedTests;
    }

and the progress bar and dialog:
    public JProgressBar getTestProgress() {
        progress = new JProgressBar();
        progress.setValue(0);
        progress.setVisible(true);
        progress.setStringPainted(true);
        progress.setString("Starting test run");
        return progress;
    }
   
    public JDialog getPopupBar() {
        progressPop = new JDialog();
        progressPop.setSize(300, 80);
        //progressPop.setModal(true);
        progressPop.setTitle("Running Tests");
        progressPop.setLocation(jContentPane.getWidth() /2, jContentPane.getHeight() /2);
        JDialog.setDefaultLookAndFeelDecorated(true);
        progressPop.add(getTestProgress());
        return progressPop;
    }
0
 
k41d3nAuthor Commented:
I was also thinking I could increment the progress bar based on the number of total test to be run (the list count) on a 100% scale.

Does that make sense?
0
 
k41d3nAuthor Commented:
In this:

                                int status = allSelected.size();
                                for (Iterator it = allSelected .iterator(); it.hasNext(); ) {
                                    Object element = it.next();
                                    String testName = element.toString();
                                    progress.setString("Running: " + testName);
                                    System.out.println("Running: " + testName);
                                    test.runTest(tr, testName);                                  
                                }

Something that takes the total number of tests, and for each one calculates the percentage of 100...

God my brain is on hold today, Simple math!
0
 
k41d3nAuthor Commented:
Technically you answered the question, I'm having another issue.
0
 
CEHJCommented:
:-)

>>I'm having another issue.

What's that?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.