Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: progress bar problem

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default progress bar problem

    Hi.. I'm new to java, I'm making application to append binary codes.
    Whenever I press the execute, the program seems like stopped but it doesn't. That's why I want to make progress bar for it.

    My code is

    /*
     * BinergabungView.java
     */
     
    package binergabung;
     
    import java.awt.Color;
    import org.jdesktop.application.Action;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import java.io.FileNotFoundException;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.io.File;
     
    import java.awt.Toolkit;
    import java.awt.Image;
    import java.awt.Cursor;
     
    import javax.swing.ProgressMonitor;
     
    /**
     * The application's main frame.
     */
    public class BinergabungView extends FrameView {
     
        public BinergabungView(SingleFrameApplication app) {
            super(app);
            initComponents();      
     
            Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
            //Image icon = Toolkit.getDefaultToolkit().getImage(this.getFrame().getClass().getResource("/icon.gif"));
            this.getFrame().setIconImage(icon);
     
            this.getFrame().setResizable(false);
            this.getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
     
        int counter = 0;
     
        class ProgressMonitor implements Runnable{
            public void run() {
                //run untill 100% complete
                while(counter < 100){
                    //update the progressbar
                    progress.setValue(++counter);
                    try {
                        //Sleep for .25 second
                        Thread.sleep(10);
                    } catch (InterruptedException ex) {}
                }
                System.out.println("We're done!");
            }
        }
     
     
        @Action
        public void gabung()
        {
            //create a new thread running a ProgressMonitor and start it
            new Thread(new ProgressMonitor()).start();
     
     
            String input1, input2, hasil;
            JFrame mainFrame = BinergabungApp.getApplication().getMainFrame();
     
            input1 = teks1.getText();
            input2 = teks2.getText();
            hasil = teks3.getText();
     
            if (input1.isEmpty())
            {
                status.setForeground(Color.RED);
                status.setText("Error : Please choose image file");
            }
     
            else if (input2.isEmpty())
            {
                status.setForeground(Color.RED);
                status.setText("Error : Please choose archive file");
            }
     
            else if (hasil.isEmpty())
            {
                status.setForeground(Color.RED);
                status.setText("Error : Please choose saved file");
            }
     
            else
            {
                status.setForeground(Color.BLUE);
                status.setText("Status : Processing..");
                mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     
                try
                {
                    FileInputStream fstream1 = new FileInputStream(input1);
                    FileInputStream fstream2 = new FileInputStream(input2);
     
                    DataInputStream in1 = new DataInputStream(fstream1);
                    DataInputStream in2 = new DataInputStream(fstream2);
     
                    FileOutputStream fos = new FileOutputStream(hasil, false);
     
                    while (in1.available() !=0)
                    {
                        fos.write(in1.readByte());
                    }
     
                    status.setForeground(Color.BLUE);
                    status.setText("Status : 50% Done");
     
                    while (in2.available() !=0)
                    {
                        fos.write(in2.readByte());
                    }
     
                    fos.close();
                    in1.close();
                    in2.close();
     
                    status.setForeground(Color.BLUE);
                    status.setText("Status : Completed");
                }
                catch(FileNotFoundException ex)
                {
                    System.out.println("FileNotFoundException : " + ex);
                    status.setForeground(Color.RED);
                    status.setText("Error : File not found");
                }
                catch(IOException ioe)
                {
                    System.out.println("IOException : " + ioe);
                    status.setForeground(Color.RED);
                    status.setText("Error : IO error");
                }
     
                mainFrame.setCursor(Cursor.getDefaultCursor());
            }
        }
     
        @Action
        public void browsefile(JTextField kotak, String status)
        {
            int pilih = bokspilih.showDialog(bokspilih, status);
     
            if (pilih == bokspilih.APPROVE_OPTION)
            {
                File file = bokspilih.getSelectedFile();
     
                try
                {
                    kotak.setText(file.getAbsolutePath());
     
                    if (!teks1.getText().isEmpty() && !teks2.getText().isEmpty() && !status.equalsIgnoreCase("save"))
                    {
                        String namafile, ekstensi;
     
                        namafile = teks1.getText();
                        namafile = namafile.trim();
     
                        int posisi = namafile.lastIndexOf(".");
                        ekstensi = namafile.substring(posisi);
     
                        if (0 < posisi && posisi <= namafile.length() - 2 )
                        namafile = namafile.substring(0, posisi);
     
                        namafile = namafile.concat("-muxed").concat(ekstensi);
                        teks3.setText(namafile);
                    }
                }
                catch(Exception e)
                {
                    System.out.println(e.getMessage());
                }
     
            }
        }
     
        @Action
        public void showAboutBox() {
            if (aboutBox == null) {
                JFrame mainFrame = BinergabungApp.getApplication().getMainFrame();
                aboutBox = new BinergabungAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            }
            BinergabungApp.getApplication().show(aboutBox);
        }
     
        /** 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();
            teks1 = new javax.swing.JTextField();
            teks2 = new javax.swing.JTextField();
            teks3 = new javax.swing.JTextField();
            tombol = new javax.swing.JButton();
            browse1 = new javax.swing.JButton();
            browse2 = new javax.swing.JButton();
            browse3 = new javax.swing.JButton();
            status = new javax.swing.JFormattedTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            statusPanel = new javax.swing.JPanel();
            progress = new javax.swing.JProgressBar();
            menuBar = new javax.swing.JMenuBar();
            javax.swing.JMenu fileMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
            javax.swing.JMenu helpMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
            bokspilih = new javax.swing.JFileChooser();
     
            mainPanel.setName("mainPanel"); // NOI18N
     
            teks1.setEditable(false);
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(binergabung.BinergabungApp.class).getContext().getResourceMap(BinergabungView.class);
            teks1.setText(resourceMap.getString("teks1.text")); // NOI18N
            teks1.setName("teks1"); // NOI18N
     
            teks2.setEditable(false);
            teks2.setText(resourceMap.getString("teks2.text")); // NOI18N
            teks2.setName("teks2"); // NOI18N
     
            teks3.setEditable(false);
            teks3.setText(resourceMap.getString("teks3.text")); // NOI18N
            teks3.setName("teks3"); // NOI18N
     
            javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(binergabung.BinergabungApp.class).getContext().getActionMap(BinergabungView.class, this);
            tombol.setAction(actionMap.get("gabung")); // NOI18N
            tombol.setText(resourceMap.getString("tombol.text")); // NOI18N
            tombol.setName("tombol"); // NOI18N
     
            browse1.setText(resourceMap.getString("browse1.text")); // NOI18N
            browse1.setActionCommand(resourceMap.getString("browse1.actionCommand")); // NOI18N
            browse1.setName("browse1"); // NOI18N
            browse1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    browse1ActionPerformed(evt);
                }
            });
     
            browse2.setText(resourceMap.getString("browse2.text")); // NOI18N
            browse2.setName("browse2"); // NOI18N
            browse2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    browse2ActionPerformed(evt);
                }
            });
     
            browse3.setText(resourceMap.getString("browse3.text")); // NOI18N
            browse3.setName("browse3"); // NOI18N
            browse3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    browse3ActionPerformed(evt);
                }
            });
     
            status.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createCompoundBorder(), javax.swing.BorderFactory.createEtchedBorder()));
            status.setEditable(false);
            status.setForeground(resourceMap.getColor("status.foreground")); // NOI18N
            status.setText(resourceMap.getString("status.text")); // NOI18N
            status.setName("status"); // NOI18N
     
            jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
     
            jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N
     
            jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
            jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
            jLabel3.setName("jLabel3"); // NOI18N
     
            jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
            jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
            jLabel4.setName("jLabel4"); // NOI18N
     
            statusPanel.setBackground(resourceMap.getColor("statusPanel.background")); // NOI18N
            statusPanel.setName("statusPanel"); // NOI18N
     
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 387, Short.MAX_VALUE)
            );
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 13, Short.MAX_VALUE)
            );
     
            progress.setName("progress"); // NOI18N
     
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2)
                                        .addComponent(jLabel3)
                                        .addComponent(jLabel1))
                                    .addGap(13, 13, 13))
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(teks2)
                                        .addComponent(teks1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(status)
                                        .addComponent(teks3, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(browse3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(browse1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(browse2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addGap(78, 78, 78)
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tombol))))
                    .addContainerGap(13, Short.MAX_VALUE))
                .addComponent(statusPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(teks1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(browse1))
                            .addGap(26, 26, 26))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4)
                            .addGap(18, 18, 18)))
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(teks2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(browse2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addGap(34, 34, 34)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(teks3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(browse3)
                        .addComponent(jLabel3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(1, 1, 1)
                    .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(tombol)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            menuBar.setBackground(resourceMap.getColor("menuBar.background")); // NOI18N
            menuBar.setName("menuBar"); // NOI18N
     
            fileMenu.setBackground(resourceMap.getColor("fileMenu.background")); // NOI18N
            fileMenu.setForeground(resourceMap.getColor("fileMenu.foreground")); // NOI18N
            fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
            fileMenu.setName("fileMenu"); // NOI18N
     
            exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
            exitMenuItem.setName("exitMenuItem"); // NOI18N
            fileMenu.add(exitMenuItem);
     
            menuBar.add(fileMenu);
     
            helpMenu.setBackground(resourceMap.getColor("helpMenu.background")); // NOI18N
            helpMenu.setForeground(resourceMap.getColor("helpMenu.foreground")); // NOI18N
            helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
            helpMenu.setName("helpMenu"); // NOI18N
     
            aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
            aboutMenuItem.setName("aboutMenuItem"); // NOI18N
            helpMenu.add(aboutMenuItem);
     
            menuBar.add(helpMenu);
     
            bokspilih.setName("bokspilih"); // NOI18N
     
            setComponent(mainPanel);
            setMenuBar(menuBar);
            setStatusBar(statusPanel);
        }// </editor-fold>
     
        private void browse1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
            this.browsefile(teks1, "Open");
    }                                       
     
        private void browse2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
            this.browsefile(teks2, "Open");
        }                                       
     
        private void browse3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
            this.browsefile(teks3, "Save");
        }                                       
     
        // Variables declaration - do not modify
        private javax.swing.JFileChooser bokspilih;
        private javax.swing.JButton browse1;
        private javax.swing.JButton browse2;
        private javax.swing.JButton browse3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JPanel mainPanel;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JProgressBar progress;
        private javax.swing.JFormattedTextField status;
        private javax.swing.JPanel statusPanel;
        private javax.swing.JTextField teks1;
        private javax.swing.JTextField teks2;
        private javax.swing.JTextField teks3;
        private javax.swing.JButton tombol;
        // End of variables declaration
     
        private JDialog aboutBox;
    }

    The problem is the progress bar is not working, I've read about making new progress monitor thread in java-forums.org/new-java/19903-trying-use-progress-bar-first-time.html but it's not working also.

    What I mean not working is, the progress bar not started when I press the execute button. But after the execution finished, the progress monitor already full.

    As you can see I'm using setText to change the status to 'processing'
    status.setText("Status : Processing..");
    But the status never come out..

    After that status I set wait cursor to it
    mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    And it's working..

    Why setting cursor working but not with the text and progress bar?

    I'm using netbeans 6.7.1

    Hope you can help thanks..


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,266
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: progress bar problem

    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Lesson: Concurrency (The Java™ Tutorials > Essential Classes)

    First, if your browseFile function takes a long time you should do it in a different thread so the GUI doesn't lock up. Right now it is in the Event Dispatch thread (EDT), which is why the text isn't updating, and probably why the progress bar isn't updating. Second, you shouldn't make calls to swing gui components from threads that are not the EDT - eg your progress bar updating (unless the API says they are thread safe) - these calls should be sent to the EDT using SwingUtilities (or you can use the SwingWorker class).

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: progress bar problem

    Quote Originally Posted by copeg View Post
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Lesson: Concurrency (The Java™ Tutorials > Essential Classes)

    First, if your browseFile function takes a long time you should do it in a different thread so the GUI doesn't lock up. Right now it is in the Event Dispatch thread (EDT), which is why the text isn't updating, and probably why the progress bar isn't updating. Second, you shouldn't make calls to swing gui components from threads that are not the EDT - eg your progress bar updating (unless the API says they are thread safe) - these calls should be sent to the EDT using SwingUtilities (or you can use the SwingWorker class).
    Is this code not making new thread?
    new Thread(new ProgressMonitor()).start();

    I don't quote understand what you say about EDT.. I made the GUI using drag and drop function in netbeans.

    I can make it working with this code in addition
    this.getFrame().repaint();
    this.getFrame().paintAll(null);

    but I got errors in command line..
    Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException
            at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665)
            at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
            ... 27 more
    Caused by: java.lang.NullPointerException
            at java.awt.Component.paintAll(Component.java:3038)
            at binergabung.BinergabungView.gabung(BinergabungView.java:70)
            ... 32 more

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,266
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: progress bar problem

    Read the two lessons I linked to in my first post to understand Threads in java. Yes you are making a new thread, but all you are doing is updating the progress bar in it...all the while the event dispatch thread is clogged up with your actionPerformed method. actionPerformed is called from the EDT (and thus in your original code so is the browseFile function). Any calls from within the EDT get placed in the EDT queue and cannot run until actionPerformed (and any function within it) finish.
    Last edited by copeg; October 22nd, 2009 at 11:37 AM.

  5. #5
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: progress bar problem

    Quote Originally Posted by copeg View Post
    Read the two lessons I linked to in my first post to understand Threads in java. Yes you are making a new thread, but all you are doing is updating the progress bar in it...all the while the event dispatch thread is clogged up with your actionPerformed method. actionPerformed is called from the EDT (and thus in your original code so is the browseFile function). Any calls from within the EDT get placed in the EDT queue and cannot run until actionPerformed (and any function within it) finish.
    Yes I understand now that I need to make new thread.
    I rewrite my code and it's working now, thanks a lot

    I rewrite my code because I can't make it work in java desktop application(the GUI that generated by netbeans), so I make new normal java project. It's really pain designing the GUI using the normal java project..

    I hope I can somehow make it working in it.. It's not working in java desktop because it conflicts with runnable and actionlistener.

    Sorry I'm new to java so I don't really now what I'm talking about

Similar Threads

  1. Progress bar while uploading a file in web application
    By jazz2k8 in forum AWT / Java Swing
    Replies: 4
    Last Post: July 8th, 2008, 07:32 AM