Displaying progress bar while components load

I'm going to display a JTree that's quite huge (takes time to load; I need to get the info as XML from a server, etc.)
So, I want to display a JProgressBar while it is loading.
My plan was to use a cardlayout, and show the panel with the progress bar until the tree was loaded and then do a .show("tree") on the main panel with the card layout.
However, this does not seem to work. Nothing is displayed before the tree is loaded ...
Any suggestions on best ways to do this?
Here's my class so far:
public class HierarchyJTree extends JPanel {
    private static Logger logger = Logger.getLogger(HierarchyJTree.class);
    private JProgressBar progress;          // keep track on progress
    private TreeMap idmap = new TreeMap(); // to map nodes created up against their id's; needed to create the tree structure when we have a parent id and want the node
    private dataAccess access = dataAccess.getInstance();
    private JTree tree;
    private CardLayout card = new CardLayout();
    private int maxProgress = 20;
     * Construct a new JTree. Collect the category information from the database.
    public HierarchyJTree() {
        this.setLayout(card);
        JPanel progressPanel = new JPanel();
        progress = new JProgressBar(0,maxProgress);
        progressPanel.add(progress);
        this.add(progressPanel, "progress");
        card.show(this,"progress");
    public void startCollectingData() {
        progress.setValue(2);
        ResultSet rs = access.sendXML("<request>\n<runQuery>getCategories</runQuery>\n</request>");
        progress.setValue(10);
        tree = new JTree(new DefaultMutableTreeNode("Categories", true));
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        JPanel treePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        treePanel.add(tree);
        this.add(treePanel, "tree");
        addFromResultSetToTree(rs);
        card.show(this, "tree");
     * Constructor that will use incomming ResultSet to create the tree, instead of contacting
     * the server to get a new one
     * @param resultset containing the category info from MOD_category
    public HierarchyJTree(ResultSet resultset) {
        this.setLayout(card);
        tree = new JTree(new DefaultMutableTreeNode("Categories", true));
        BasicConfigurator.configure();
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        addFromResultSetToTree(resultset);
     * This will take a jaxb.ResultSet object containing ID, categoryName and parentID of all the
     * categories in the database, and add them as Nodes in the JTree this class represents.
     * @param r the jaxb.ResultSet object
    private void addFromResultSetToTree(ResultSet r) {
         // code to load the info into the tree here, and inc the progress
            progressValue += incValue;
            progress.setValue((int)Math.round(progressValue));
}

Use SwingWorker, which is not included in Swing library, but you can find it on http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/SwingWorker.java;
see alse http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html.

Similar Messages

  • Show progress bar while module loads

    I have a TabView where each tab is a module. One of the
    modules has a lot of child components and when I click to activate
    that tab - it takes 2-3 seconds to load. During this time OSX shows
    the beach ball.
    Is it possible for me to show a loading progress bar instead?
    Should I be pre-loading all the modules when the application loads,
    or at some other point? If so, how do I do this?
    Any suggestions would be appreciated.

    Hey Jason,
    I'm not sure who moderates, but I can send you in the right
    direction.
    Short answer: Look around for Asynchronous Flex demos
    Long answer:
    The interfaces locks up (beach ball/hour glass) because the
    main application 'thread' is busy with the task you asked of it.
    This can, in many different languages, cause a freeze. Javascript,
    Native Mac or Windows applications, apparently Flex too.
    Running one task at a time is considered a synchronous
    (serial) request. What you need to do is make an asynchronous
    (parallel) request. In the web world, that's the 'A' in Ajax. By
    making asynchronous requests, you free up the main 'thread', while
    a separate worker thread is off completing the task. This keeps
    your interface responsive.
    I think that leads to event listeners.. Send off a background
    request, but listen for it to complete. Link the listener to a
    second piece of code upon successful completion.
    I wish I could get into more detail, but I'm not a Flex guy..
    hoped that at least helped gel the idea.
    -dp

  • Progress bar while PDF loading on browser

    Hi,
    I have a servlet which is getting the data and rendering a PDF form and display the form into user's browser. I want to show a progress bar or a waiting image/message on the browser when a rendered PDF is loading. I found out that there is no delay in any step of the code itself but the PDF is taking time to load in a browser and this delay is increased when I apply reader extensions on rendered PDF. Is there any way to show a progress because the delay is too much.
    Regards,
    Sunaif Aziz

    I resolved this when page loads but i still have issue with a progress bar on another page displaying "before" onload...thanks.

  • Displaying an Indeterminate Progress Bar While a DB2 Stored Proceedure Runs

    How do I display a dialog with an indeterminate progress bar while a DB2 query runs? Could anyone point me to an example or some strong docs?
    I learned Java about six months ago, so I'm relatively new to the language. Through searching and documentation, I've been able to find all the examples and answers I've needed so far. Now I've run into an issue I can't find anywhere. It seems like the most basic thing in the world. I have a DB2 stored procedure that takes about 5 minutes to run. While it's running, I want to display a simple dialog with a progress bar going back and forth (no buttons, no user interaction).
    I'm using Eclipse 3.3.1.1 as my IDE, and running the application from a JAR file. I have Java 1.6.0.30 installed. The DB2 query is running in response to a user clicking a button on the form (an ActionEvent). All of my forms are using Swing (JFrame, JDialog, etc.).
    The crux of my problem seems to be that I can bring up a dialog (which should contain the progress bar), but I can't get it to paint. All I get is a window that's the right size/location, but contains an after-image of what was behind it. I can't even get a dialog to display with a "Please Wait" label while the DB2 procedure runs.
    I tried separating both the DB2 stored procedure and the progress dialog into separate threads. I tried yielding in the DB2 thread to give the progress dialog a chance to update. I tried using invokeAndWait, but I got the following error:
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
    It seems like I'm doing something wrong in my use of Theads, but I can't for the life of me figure out what it is. If anyone could help out a bit of a Java newbie, I would be extremely grateful.

    Demo:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ProgressBarExample2 {
        private JProgressBar bar = new JProgressBar(0,99);
        private JButton button = new JButton("Lengthy operation");
        private ActionListener al = new ActionListener(){
           public void actionPerformed(ActionEvent evt) {
                button.setEnabled(false);
                bar.setIndeterminate(true);
                new Worker().execute();
        private class Worker extends SwingWorker<Boolean, Boolean>{
            protected Boolean doInBackground() {
                try {
                    Thread.sleep(10000); //10 secs
                } catch (InterruptedException e) {
                return Boolean.TRUE;
            protected void done() {
                button.setEnabled(true);
                bar.setIndeterminate(false);
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ProgressBarExample2();
        ProgressBarExample2() {
            button.addActionListener(al);
            JPanel cp = new JPanel();
            cp.add(button);
            cp.add(bar);
            JFrame f = new JFrame("ProgressBarExample2");
            f.setContentPane(cp);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Displaying Progress Bar

    Hello,
    I want to display progress bar based on the bytes received from socket.  The tutorials and examples show only image loading.  Is it possible to display progress bar based on bytes received for socket.  If so, can anyone tell me how to do it?
    var total_bytes:Number=0;
    public function bytesReceived(event:ProgressEvent):void
           var bytes_received = event.bytes.loaded;
           total_bytes = bytes_received + total_bytes;
    Thanks

    Use SwingWorker, which is not included in Swing library, but you can find it on http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/SwingWorker.java;
    see alse http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html.

  • How can i Create a PROGRESSIVE BAR   while process of a procedure is going

    hi,
    I have a push button in my form that runs the procedure .the process will approx 15 minutes. while processing is started, i want to display PROGRESSIVE BAR
    until process complete and exits automatically after process . please suggest me how to create the same, is it possible..
    please send me solution as soon as possible please
    thanks in advance
    prasanth

    The forms demos contains a progress bar bean which you can use if web deployed.
    Regards
    Grant Ronald
    Forms Product Management

  • HT4718 I can't reach recovery system when I reboot- I press 'command' and 'r' quickly, but nothing happens, the progress bar begins to load... Any thoughts?

    I can't reach recovery system when I reboot- I press 'command' and 'r' quickly, but nothing happens, the progress bar begins to load... Any thoughts? It gets about halfway through loading and then stops, no mouse, no nothing. I think I'll be able to move past it if I can reach the Recovery options.
    Thanks!

    If you are really sure that it's impossible to click in Recovery mode, then something is wrong with the machine.
    Make a "Genius" appointment at an Apple Store, or go to another authorized service provider.
    Back up all data on the internal drive(s) before you hand over your computer to anyone. There are ways to back up a computer that isn't fully functional — ask if you need guidance.
    If privacy is a concern, erase the data partition(s) with the option to write zeros* (do this only if you have at least two complete, independent backups, and you know how to restore to an empty drive from any of them.) Don’t erase the recovery partition, if present.
    Keeping your confidential data secure during hardware repair
    Apple also recommends that you deauthorize a device in the iTunes Store before having it serviced.
    *An SSD doesn't need to be zeroed.

  • PROGRESS BAR WHILE LOADING A PAGE

    All,
    iam using below code and its working good with page submit button but i need it for a page load i.e when a page loads show the progress bar(page which take a while to load) so i can call it like onload. Anybody who has done this pls i appreciate if you could help...
    function html_Submit_Progress(pThis){ 
    $x_Show('AjaxLoading');
    window.setTimeout('$s("AjaxLoading",$x("AjaxLoading").innerHTML)', 900);
    doSubmit('APPLY_CHANGES');
    function submit_HideAll(pThis){ 
    $x_Hide('wwvFlowForm');
    doSubmit('APPLY_CHANGES');
    function submit_ButtonRegion(pThis){ 
    $x_Hide('button_region');
    doSubmit('APPLY_CHANGES');
    using apex 4.1 and my page here i need it is a popup.
    thanks

    You can fix that in your page template by putting something like this just before the BODY tag in the Header region:
    <div id="loading"
      style="display: block;
             position: fixed;
             top: 0px;
             left: 0;
             z-index: 1999;
             width: 100%;
             height: 100%;
             background-color: #fff;
             text-align: center;">
    <div style="position: relative;
                top: 130px;">
    Wait..loading..
    </div>
    <img src="#IMAGE_PREFIX#themes/theme_200/images/loading.gif" height="32" width="32"
       style="position: relative;
              top: 150px;"/>
    </div>and putting something like this just after the closing BODY tag in the Footer region:
    <script>
    $(document).ready(function(){
      $('#loading').hide();
    </script>

  • PROGRESS BAR while loading report

    Hi Fiends,
    I have a classic report w/ a link and this link open a other page and this page is a report with a report model ( CSV ).. and this load is too slow and i wanna include a progress bar like this site [link]http://apex.oracle.com/pls/otn/f?p=987654321:26[link] and this progress bar will be show while the report is loading ...
    Anybody knows how to do this ?
    Tks
    Zander

    Hi,
    Have you seen :
    [url http://apex.oracle.com/pls/otn/f?p=65560:2:0::NO] Loading Icon plugin
    [url http://www.apex-plugin.com/oracle-apex-plugins/dynamic-action-plugin/loading-icon_81.html]Click here to see the features and download
    And I think that it is good to check [url http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_plsql_job.htm#AEAPI1203]APEX_PLSQL_JOB
    Regards,
    Fateh
    Edited by: Fateh on Sep 22, 2012 1:26 AM

  • Progress bar while loading table

    Hi, please could anyone help me to how to create progress bar when i am loading large number of data using bean. data would be unknown so how do i show the status...plz help..
    thanks

    This should help
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

  • Show Progress Bar while only on Page Load.

    Hi Experts,
    I want to show progress bar every time when page loads.
    Progress bar is coming on the page. but it is not going off after page is loaded.
    Below is the code which i added for the Progress bar.
    //written on Header Text of Page
    <script type="text/javascript">
    <!--
    function html_Submit_Progress(pThis){
    $x_Show('AjaxLoading');
    window.setTimeout('$s("AjaxLoading",$x("AjaxLoading").innerHTML)', 100);
    //-->
    </script>
    //written on footer text of Page
    <style> #AjaxLoading{padding:5px;font-size:18px;width:200px;text-align:center;left:20%;top:20%;position:absolute;border:0px solid #666;}
    </style>
    <div id="AjaxLoading" style="display:none;"><br /><img src="#APP_IMAGES#progress_bar.gif" id="wait" /></div>
    //called the function Execute on Page Loads 
    html_Submit_Progress(this);Progress bar is continuously showing on the page after page is loaded.
    I want only to show only page loads.
    Please help me .
    Apex Version : Apex 4.1
    DB Version : 10g
    Regards,
    Jitendra

    Hide the loader element when the page has loaded. Put this in the javascript section
    $(document).ready(function(){ $x_Hide('AjaxLoading'); });Or put it in the page load section
    $x_Hide('AjaxLoading');Or create a dynamic action which fires on page load, select a hide action, and use a jQuery selector to target '#AjaxLoading' as an affected element.

  • No progress bar while music is playing?

    since i've upgraded my 3g to 2.2, i've noticed that while music is playing, there is no progress bar @ the top(like the volume bar @ the bottom).
    my g/f also has her iphone 3g running 2.2, but her progress bar is still there, along with the little genius logo, which i also no longer have...
    is this a setting issue, or a firmware problem?
    as a DJ, its helpful to have the progress bar so that i can skip thru a song
    thanks for any help

    Tap the artwork while the song is playing to display the additional controls.
    See http://manuals.info.apple.com/enUS/iPhone_UserGuide.pdf, page 63.

  • Progress bar while downloading data

    I want a progress bar showing while I'm downloading data. This seems like a simple thing but I can't figure it out. If I show() the progress bar before and/or during the download it becomes a blank frame. I should probably use a thread, but I don't know the best way to go about it. Any suggestions?

    Any suggestions?Maybe try looking at the javadocs?:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JProgressBar.html
    which would have led you here:
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

  • Display progress bar and message for delay

    hi all,
        I have an application in which, when i execute the RFC it is taking time to get the data. So it is displaying a white screen for the user untill the data is retrieved from the backend.
    I want to show a progress bar or any thing of that kind so that user knows that data is being loaded.
    Is there a way to do that?
    Regards,
    Gopi

    Hi,
       You might want to go through <a href="/people/valery.silaev/blog/2006/10/09/loading-please-wait blog.
    Regards,
    Satyajit.

  • Creating a progress bar while querying a report in Visual Studio

    I have created a Visual Studio 2013 program that runs reports from a SQL server.  I want a progress bar to show up in my VS program while it is querying so my user doesn't think that it is frozen while running larger queries.  How can I do this.
     Step by step is better since I am new to programming.
    Gracies 
    Much Love 

    Hi flextera,
    Based on your description, I’m afraid that it is not the correct forum for this issue, since this forum is to discuss:
    Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.
    To make this issue clearly, would you mind letting us know more information about this issue? Which language are you using? Which kind of app are you developing? You said that it is related to the report in SQL Server, is it the SSRS issue or the specific
    windows app like the WinForms app?
    Please share me more information, I will help you find the correct forum for this issues.
    If there's any concern, please feel free to let me know.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • My devices not automatically switching between Airport Extreme and Airport Express in extended network

    I have setup an extended network in my home using an Airport Extreme and an Airport Express. The Extreme is connected directly to the FiOS modem and the Express is being used as the extender. The nework is setup fine, but my devices (MBA, iPhone, iPa

  • How could i use resource bundle in managed bean instead of harding coding?

    component is created in managed bean programmatically, so how to set attributes(e.g. text, value) using resource bundling instead of hard coding, as like coding on the page directlly? Thanks for your help! Kevin.

  • Animation Priority over Actionscript

    I have been working on a bit of flash that can load html strings from a database using a combination of php and mysql. As flash does not use the <table> tag, I was forced to look for other options. I luckily found a nice script that can create a make

  • Java iView Runtime error while login

    Hi, We are facing with a problem while logging on to the SAP Portal 7.0. We are not just facing with this problem on Portal logon, the other J2EE applications also, such as useradmin. The problem arises as soon as we logon to the Portal. Please find

  • How can i reset Bridge CS6 to its default settings?

    Hello, i have a problem with Bridge CS6. Somehow its very slow and lags. when i tried to open a folder it takes sometimes several minutes before anything happens. is there a way to reset bridge to its default settings without reinstalling? Thanks