?
Solved

JProgress bar that pops up

Posted on 2005-05-13
10
Medium Priority
?
250 Views
Last Modified: 2013-11-28
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?
0
Comment
Question by:k41d3n
  • 5
  • 4
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 13996523
Modal JDialog - put a JProgressBar on it
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13996530
0
 
LVL 2

Author Comment

by:k41d3n
ID: 13996899
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
Sign your company up to try the MB 660 headset now

Take control and stay focused in noisy open office environments with the MB 660. By reducing background noise, you can revitalize your office and improve concentration.

 
LVL 86

Expert Comment

by:CEHJ
ID: 13997264
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13997280
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
 
LVL 2

Author Comment

by:k41d3n
ID: 13997330
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
 
LVL 2

Author Comment

by:k41d3n
ID: 13997352
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
 
LVL 2

Author Comment

by:k41d3n
ID: 13997378
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
 
LVL 2

Author Comment

by:k41d3n
ID: 13999000
Technically you answered the question, I'm having another issue.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13999021
:-)

>>I'm having another issue.

What's that?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
There is a massive demand for content on the web right now, and it doesn't look like it's going to stop any time soon. But, if you are running a business blog, it's not just enough to offer your audience lots of content. It needs to be high-quality…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question