Results 1 to 8 of 8

Thread: JprogressBar

  1. #1
    cotarelo is offline Member
    Join Date
    Mar 2010
    Posts
    43
    Rep Power
    0

    Default JprogressBar

    Hi,

    I am trying to do a progress bar. I started with the netbeans java desktop application.

    I dont know why but when I write:

    Java Code:
    progressBar.setValue(100);
    Does not produce any results in my progress bar.

    Anyone knows why?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cotarelo View Post
    Hi,

    I am trying to do a progress bar. I started with the netbeans java desktop application.

    I dont know why but when I write:

    Java Code:
    progressBar.setValue(100);
    Does not produce any results in my progress bar.

    Anyone knows why?
    You've got a bug. Where, I've no idea other than that it's not in the code you've posted. Again, this is where an SSCCE would help us come up with a solution quickly. Otherwise it's up to you to debug. Much luck.

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    wait a minute...
    Is your progress bar filled up?
    What you mean saying "cannot see any results"?

  4. #4
    cotarelo is offline Member
    Join Date
    Mar 2010
    Posts
    43
    Rep Power
    0

    Default

    No, the progress bar stays there, without any visual results of any type

    Here is the code, the line I am referring is in the method goButtonActionPerformed

    Java Code:
    package progressbartest;
    
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    import javax.swing.Icon;
    
    /**
     * The application's main frame.
     */
    public class ProgressBarTestView extends FrameView {
    
        public ProgressBarTestView(SingleFrameApplication app) {
            super(app);
    
            initComponents();
    
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
    
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            mainPanel = new javax.swing.JPanel();
            goButton = new javax.swing.JButton();
            statusPanel = new javax.swing.JPanel();
            javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
            statusMessageLabel = new javax.swing.JLabel();
            statusAnimationLabel = new javax.swing.JLabel();
            progressBar = new javax.swing.JProgressBar();
    
            mainPanel.setName("mainPanel"); // NOI18N
    
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(progressbartest.ProgressBarTestApp.class).getContext().getResourceMap(ProgressBarTestView.class);
            goButton.setText(resourceMap.getString("goButton.text")); // NOI18N
            goButton.setName("goButton"); // NOI18N
            goButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    goButtonActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGap(178, 178, 178)
                    .addComponent(goButton)
                    .addContainerGap(192, Short.MAX_VALUE))
            );
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                    .addContainerGap(124, Short.MAX_VALUE)
                    .addComponent(goButton)
                    .addGap(120, 120, 120))
            );
    
            statusPanel.setName("statusPanel"); // NOI18N
    
            statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
    
            statusMessageLabel.setName("statusMessageLabel"); // NOI18N
    
            statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
    
            progressBar.setName("progressBar"); // NOI18N
    
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 214, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel)
                    .addContainerGap())
            );
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(3, 3, 3))
            );
    
            setComponent(mainPanel);
            setStatusBar(statusPanel);
        }// </editor-fold>
    
        private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            progressBar.setValue(100);
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton goButton;
        private javax.swing.JPanel mainPanel;
        private javax.swing.JProgressBar progressBar;
        private javax.swing.JLabel statusAnimationLabel;
        private javax.swing.JLabel statusMessageLabel;
        private javax.swing.JPanel statusPanel;
        // End of variables declaration
    
        private final Timer messageTimer;
        private final Timer busyIconTimer;
        private final Icon idleIcon;
        private final Icon[] busyIcons = new Icon[15];
        private int busyIconIndex = 0;
    }
    Last edited by cotarelo; 03-24-2010 at 09:07 AM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default

    Uncompilable IDE generated code neither helps you to learn Swing nor is conducive to getting help on a forum. Recommended reading (in no particular order)
    SSCCE : Java Glossary
    How To Ask Questions The Smart Way
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    In that monstrosity of code, you seem to have a couple of Timers. One of them is probably resetting any progress balue you set elsewhere.

    db

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    No, the code like a

    Java Code:
    private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            progressBar.setValue(100);
        }
    wouldn't work because you have to use

    a) DefaultBoundedRangeModel(from,0,0,to)
    b) put the progress bar filling in sep. thread. public void run(){} method
    c) controll it's processing with a loop like a while()

  7. #7
    cotarelo is offline Member
    Join Date
    Mar 2010
    Posts
    43
    Rep Power
    0

    Default

    Thanks for the reply! I am still trying but I get no results.

    I declared in the class
    Java Code:
    DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(0, 0, 0, 100);
    then on the initcomponents

    Java Code:
           progressBar = new javax.swing.JProgressBar(model);
    and then inside the goButtonActionPerformed method
    Java Code:
    new Thread() {
    
            public void run() {
            int value = progressBar.getValue() + 7;
            if (value > progressBar.getMaximum()) {
              value = progressBar.getMaximum();
            }
            progressBar.setValue(value);
    
    
    
            }
            }.start();
    It compiles without errors but it does not show progress bar.

    Could you give me an example?
    Thanks!

  8. #8
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    for a positive feedback of course :)

    instructions
    Last edited by Webuser; 03-26-2010 at 03:20 AM.

Similar Threads

  1. JProgressBar inside a JDialog
    By Mikey_S in forum AWT / Swing
    Replies: 10
    Last Post: 07-13-2009, 02:55 PM
  2. Updating a JProgressBar from another thread?
    By Xiphias in forum AWT / Swing
    Replies: 3
    Last Post: 03-18-2009, 01:48 AM
  3. Placing a JProgressBar over my JPEG image
    By hitmen in forum AWT / Swing
    Replies: 7
    Last Post: 03-08-2009, 10:16 AM
  4. [SOLVED] Netbeans Desktop App &amp; JProgressBar
    By SebScoFr in forum NetBeans
    Replies: 3
    Last Post: 11-27-2008, 11:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •