ProgressBar is not working

Hello! I am trying to indicate ProgressBar during download the binary file. But ProgressBar is not working.Please help me!
* BinarySaver6.java
* Created on 2003/08/30, 14:46
import java.net.*;
import java.io.*;
* @author masaki
public class BinarySaver6 extends javax.swing.JFrame {
/** Creates new form BinarySaver6 */
public BinarySaver6() {
initComponents();
/** 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.
private void initComponents() {//GEN-BEGIN:initComponents
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jProgressBar1 = new javax.swing.JProgressBar();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
jTextField1.setText("http://");
getContentPane().add(jTextField1, java.awt.BorderLayout.NORTH);
jButton1.setText("DOWNLOAD");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);
jProgressBar1.setStringPainted(true);
getContentPane().add(jProgressBar1, java.awt.BorderLayout.SOUTH);
pack();
}//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
try {
URL u = new URL(jTextField1.getText());
URLConnection uc = u.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
if (contentType.startsWith("text/") || contentLength == -1 ) {
throw new IOException("This is not a binary file.");
InputStream raw = uc.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
bytesRead = in.read(data, offset, data.length-offset);
if (bytesRead == -1) break;
offset += bytesRead;
     jProgressBar1.setValue(jProgressBar1.getValue()+offset);
in.close();
if (offset != contentLength) {
throw new IOException("Only read " + offset
+ " bytes; Expected " + contentLength + " bytes");
String filename = u.getFile();
filename = filename.substring(filename.lastIndexOf('/') + 1);
FileOutputStream fout = new FileOutputStream(filename);
fout.write(data);
fout.flush();
fout.close();
catch (MalformedURLException e1) {
System.err.println(jTextField1.getText() + " is not URL I understand.");
catch (IOException e2) {
System.err.println("error");
}//GEN-LAST:event_jButton1ActionPerformed
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
* @param args the command line arguments
public static void main(String args[]) {
new BinarySaver6().show();
// �������� - ���W�s��//GEN-BEGIN:variables
private javax.swing.JTextField jTextField1;
private javax.swing.JButton jButton1;
private javax.swing.JProgressBar jProgressBar1;
// �����������I����//GEN-END:variables

Richard, you like many, many others in the forum on this thread and others fail to appreciate the real problem here, I think. Lot's of people suggest to learn to use threads and read the Swing tutorial on ProgressMonitor. That is good as far as it goes, but consider what we have here. You are right that the problem is that the event processing thread is blocked and that is what is preventing the progress bar from updating. But often what you want to do is exactly to block the event processing thread.
Consider that any application code is full of action handlers etc that manipulate some common data structure(s). Now if you want to do some operation on this data structure you want to block others from manipulating it at the same time. Now if this operation you are doing takes a long time you want to present a progress bar.
How do you do that.
If you just put it up (the progress bar), in a (non modal) window, it won't show. You do not want to put the operation into a thread and let the event processing thread run, as preventing all those other event/action handlers from manipulating the data structures would require a lot of work.
I think that putting the progress bar into a modal dialog (showing the modal dialog would block the event processing thread and thus other action/etc handlers) and creating a separate thread to do the work would work, but seems like a quite a lot of work for something that should be as simple as:
ProgressBarDialog pbar=new ProgressBarDialog());
pbar.setVisible(true);
for (as long as I like)
pbar.setValue(i++)
pbar.setVisible(false);
all this in an actionListener.actionPerformed() method.
I'm just working on that but so far have no code to share...
regs Kusti

Similar Messages

  • Javascript multiple file upload with progressbar does not work in firefox, please help

    I want to upload files using this javascript snipped as well as processing non file fields on the same form. This works beautiful in IE11, Chrome and Opera, but not in firefox (version 34).
    I fired the non file handler with the action attribute on the <form> like this:
    <form id="upload_form" enctype="multipart/form-data" method="POST" action="nonFile.php">
    and the javascript with:
    <input name="submit" type="submit" style="background: green" value="Submit" onclick="return uploadFiles()"/>
    When I change type="button" the file uploads work in FF but the I have no control over the non file fileds.
    Can someone gives me an indication of what is wrong?
    oXHR.upload.addEventListener("progress", function(e){
    var percent=(e.loaded/e.total) * 100;
    _(idProg).value = Math.round(percent);
    _(idstat).innerHTML = filename.name + " "+Math.round(percent)+"% --- Please Wait";
    }, false);
    // Upload finish, show the size of the file in Bytes, KBytes or MBytes
    oXHR.onreadystatechange = function(){
    if (oXHR.readyState == 4 && oXHR.status == 200){
    var iBytesTransfered = bytesToSize(filesize);
    _(idstat).innerHTML = filename.name + " Size: " + iBytesTransfered + " "+100+"%";
    _(idProg).value = 100;
    // Upload failed
    oXHR.addEventListener("error", function(e){
    _(idstat).innerHTML = "Upload Failed";
    }, false);
    // Upload aborted
    oXHR.addEventListener("abort", function(e){
    _(idstat).innerHTML = "Upload Aborted";
    }, false)

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0, 0,0" width="600" height="360">
    <param name=movie value="example.swf">
       <param name="allowScriptAccess" value="always" />
    <param name="quality" value="high">
    <param name="allowScript" value="opaque">
    <param name="wmode" value="opaque">
    <embed src="example.swf" quality="high" allowScriptAccess="always" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=Shockwave Flash" type="application/x-shockwave-flash" width="600" height="360"></embed></object>

  • Button not working in browser

    I am coding a video player in Netbeans 6.8. just find two problems:
    1. the browser button not working in browser when I run the project from Netbeans under "run in browser" mode. however under "standard execution" mode, everything is fine.
    2. can not run the jar file in the project's dist directory directly. in other word, I can not run the jar file outside of Netbeans.
    I appreciate any help. thanks.
    Main.fx:
    package gui;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.paint.Color.*;
    * @author Jethro
    var face=Face{};
    function run(){
        Stage{
            title: "player"
            resizable:false
            scene: Scene{
                width:800
                height:600
                fill:DARKBLUE
                content: [face]
    }Face.fx:
    package gui;
    import javafx.scene.CustomNode;
    import javafx.scene.Group;
    import javafx.scene.Node;
    import javafx.scene.control.Button;
    import javafx.scene.layout.VBox;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.MediaError;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.media.MediaView;
    import javafx.scene.control.ProgressBar;
    * @author Jethro
    public class Face extends CustomNode {
        public var lbf=LBF{};
        public var enable=true;
        public var mark="play";
        public var sourceOfMedia:String;
        public def player=MediaPlayer {
            repeatCount:MediaPlayer.REPEAT_FOREVER
            onError:function(e:MediaError){
                var er=e.message;
         media : bind Media {
              source: sourceOfMedia
        public def view=MediaView {
                mediaPlayer:bind player
                preserveRatio: true                    
        public def bar=ProgressBar {
                height:10
                width:bind scene.width
                progress: bind
                    if(player.media !=null){
                        player.currentTime.toMillis()
                            /player.media.duration.toMillis();
                    }else{
                        0.0
        public var play=Button {      
            onMousePressed:function(e:MouseEvent){
                if(enable and player.media != null){
                            mark="pause"; println("playing...");                       
                            sourceOfMedia=lbf.uri;
                            player.play();
                            enable=false;
                }else{
                    mark="play";
                    player.pause();println("paused...");
                    enable=true;
         text: bind mark       
        public override function create(): Node {
            return Group {
                content: [
                    VBox{
                        content: [
                            lbf,
                            bar,
                            play,
                            view,
    }LBF.fx:
    package gui;
    import javafx.scene.CustomNode;
    import javafx.scene.Group;
    import javafx.scene.control.TextBox;
    import javafx.scene.layout.HBox;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.text.Font;
    import javafx.scene.text.Text;
    import javafx.scene.Node;
    import javafx.geometry.HPos;
    import javafx.geometry.VPos;
    import javafx.scene.control.Button;
    import javax.swing.JFileChooser;
    * @author Jethro
    public class LBF extends CustomNode{
        public var uri:String;
        public var whereis=Text {
            fill:Color.BLUE
         font : Font {
              size: 20
         x: 10, y: 30
         content: "location: "
        public var location=TextBox{
            text:"the song's location"
            columns:40
            selectOnFocus:true
        public var browser=Button {
         text: "Browser"
         action: function() {
                    var jfc=new JFileChooser();               
              jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                    var val = jfc.showOpenDialog(null);
                    if(val == JFileChooser.APPROVE_OPTION) {                   
                        location.text = jfc.getSelectedFile().getAbsolutePath();
                        uri=jfc.getSelectedFile().toURI().toString();
                        println(location.text);
        public var face=Group {
         content: [
              Rectangle {
                        x: 0, y: 0
                        width: 800, height: 50
                        fill: Color.SILVER
                     HBox{
                         width:800
                         height:50
                         hpos:HPos.CENTER
                         vpos:VPos.CENTER
                         spacing:5
                         content: [whereis,location,browser]
        public override function create():Node{
            return face;
    }

    thanks for your reply but I need more specific operation.
    maybe I am not very clear about the problem one. I mean when I run the code in standard mode, if I click the browse button, a window will pop out and I can choose a video file from my local harddisk. but if I run it in "web start execution" mode and "run in browser" mode. the browse button make no response when I click it.
    Edited by: Phoenix2006 on Feb 8, 2010 2:35 PM
    Edited by: Phoenix2006 on Feb 8, 2010 2:37 PM
    Edited by: Phoenix2006 on Feb 8, 2010 2:42 PM

  • Preview PDF while loading not working in Reader 10

    Hi,
    a cool feature of Adobe Reader 9 was the "pdf preview while loading".
    If I opened a large PDF-Document in the webbrowser the first few pages have been displayed while the rest of the document was loaded in the background.
    This was very helpful because I was able to decide weather I would like continue loading or not.
    This feature does not work anymore with Adobe Reader 10 and Firefox.
    I have to wait until the blue progressbar is completed.
    On Internet explorer it works.
    Any tips ?
    Thank You,
    Andy.

    [topic moved to Adobe Reader for Android forum]

  • Not work tablet UI on Prestigio 5080 PRO tablet

    I read that browser.ui.layout.tablet = "1" can fix this problem. But it not works. I can work only in pnone interface that is not good for my 8'' tablet.

    Would it be possible for you to share the problematic pdf and OS information  with us at [email protected] so that we may investigate?
    Thanks,
    Adobe Reader Team

  • Why self-defined access sequences of free goods can not work?

    Hi gurus,
    I have maintained access sequences of free goods self-defined.but when i creat the SO it does not work!
    when i used the standard access sequences ,it is OK .
    Can anybody tell me why?
    thanks in advance

    Dear Sandy,
    Go to V/N1 transaction select your self defined access sequence then go in to the accesses and fields and check all fields are activated.
    Make sure that these fields are flowing in your sales order.
    I hope this will help you,
    Regards,
    Murali.

  • Adobe bridge raw not working with windows vista in photoshop cc, why?

    adobe bridge raw not working in photoshop cc, is there a fix?

    Your sure your using photoshop cc on windows vista?
    I was under the impression that photoshop cc would not even install on windows vista.
    What version of camera raw do you have?
    In photoshop under Help>About Plugin does it list Camera Raw and if so which version is it?
    (click on the words Camera Raw to see the version)
    Camera raw doesn't work if it's a camera raw file or some other file type such as jpeg or tif?
    What camera are the camera raw files from?
    Officially camera raw 8.3 is the latest version of camera raw that will work on windows vista.

  • Adobe Bridge CS5 in windows 7 not working?

    Adobe Bridge CS5 in windows 7 not working. I was using bridge perfectly for last 2 years. It stops working since 3 days. I tried to install updates. Showing some error to install.
    Tried to install creative cloud..again some error. Error code : 82
    Could you please advice how I can fix my adobe bridge.

    https://www.youtube.com/watch?v=xDYpTOoV81Q&feature=youtu.be
    please check this video I uploaded..this is what happens when I click adobe bridge.. just blinks and go off. bridge not working on task manager

  • ADOBE CLOUD ON MY DESKTOP WILL NOT WORK. IT LOADS UP BUT NOTHING FILLS THE WINDOW

    ADOBE CLOUD ON MY DESKTOP WILL NOT WORK. IT LOADS UP BUT NOTHING FILLS THE WINDOW

    BLANK Cloud Screen http://forums.adobe.com/message/5484303 may help
    -and step by step http://forums.adobe.com/thread/1440508?tstart=0
    -and http://helpx.adobe.com/creative-cloud/kb/blank-white-screen-ccp.html

  • Partner application logoff not working

    We have a partner application registered with sso with custom login screen. The login works fine. We use the following code to logoff the partner application in logoff.jsp
    response.setHeader("Osso-Return-Url", "http://my.oracle.com" );
    response.sendError(470, "Oracle SSO");
    session.invalidate();
    but the logoff is not working properly. It is not invalidating the session and the logout http request is not going from the application server to the sso server.
    Are there any additional configurations for SSO logoff.Any help is appreciated.
    Thanks

    Hi
    The WF should also trigger if i add the Partner function in UI.If i change any Attribute the WF triggers but i dont want to change the attribute when i add the partner function.
    If i have only one event for WF that is Partner Change the WF will not trigger it for the 1st time when i save the UI. But next i come to the same saved doc and add a partner function then the Wf triggers.
    So this means that Partner change is active.
    the issue here is i need to trigger the WF on , the 1st time i save the UI, for which i wil be using Attribute Change and next time when i come back to saved doc the and add only the partner function and no changes are made to attributes the WF should again trigger.
    Thanks
    Tarmeem

  • IPhone 4 Voice Memos not working/saving

    Hi there,
    I'm having trouble with my voice memos too. Up until yesterday they were working fine and now, even though the record button works, the stop button does not and I can only pause them. Worse again is that the button to go into the menu to view all voice memos is not working so I can't play them from my iPhone and nothing new is saving to my iTunes. Please help!

    I've always had the "Include Voice Memos" option selected. I think that only pertains to syncing voice memos from iTunes to the iPhone after it has been copied to iTunes. It has to be the new OS/iTunes not communicating that new memos have been recorded. For some reason they won't sync when I want them to, and then a few syncs later they magically appear.
    By the way, I'm VERY comfortable with the iTunes and iPhone systems. I've been using iTunes for 5 years, and I've been recording class lectures with the iPhone voice memo app (and another app) for a couple years. It's not an error of not seeing that the memos were added; they don't exist in my library or music folders.
    JUST OUT OF CURIOSITY, POST WHICH FIRMWARE YOU ARE RUNNING EXACTLY!!!
    I'm on an iPhone 4, running firmware 4.0.1

  • Installed Premiere Pro CS4 but video display does not work?

    I just got my copy of CS$. After installing Premiere I found two things that seem very wrong:
    1) video display does not work, not even the little playback viewer next to improted film clips located on the project / sequence window. Audio works fine.
    2) the UI is way too slow for my big beefy system.
    My pc is a dual boot Vista-32 and XP system with 4GB of memory installed and nvidia geforce 280 graphics board with plenty of GPU power. The CS4 is installed on the Vista-32 partition. My windows XP partition on the same PC with Premiere CS2 works great and real fast.
    Any ideas how to solve this CS4 install issue?
    Ron

    I would like to thank Dan, Hunt, and Haram:
    The problem is now very clear to me. The problem only shows up with video footage imported into PP CS4 encoded with "MS Video 1" codec. So this seems to be a bug. The codec is very clearly called out and supported within various menues but video with this codec just will not play in any monitor or preview window. In addition the entire product looks horrible with respect to performance while PP CS4 trys its best to play the video. Audio will start playing after about 30 seconds. And once in awhile part of video shows up at the wrong magnification before blanking out again.
    My suggestion to the Adobe team: fix the bug and add some sample footage to the next release so new installations can test their systems with known footage.
    My PC is brand new with the following "beefy" components:
    Motherboard
    nForce 790i SLI FTW
    Features:
    3x PCI Express x16 graphics support
    PCI Express 2.0
    NVIDIA SLI-Ready (requires multiple NVIDIA GeForce GPUs)
    DDR3-2000 SLI-Ready memory w/ ERP 2.0 (requires select third party system memory)
    Overclocking tools
    NVIDIA MediaSheild w/ 9 SATA 3 Gb/sec ports
    ESA Certified
    NVIDIA DualNet and FirstPacket Ethernet technology
    Registered
    CPU: Intel Core 2 Quad Q9550
    S-Spec: SLAWQ
    Ver: E36105-001
    Product Code: BX80569Q9550
    Made in Malaysia
    Pack Date: 09/04/08
    Features:
    Freq.: 2.83 GHz
    L2 Cache: 12 MHz Cache
    FSB: 1333 MHz (MT/s)
    Core: 45nm
    Code named: Yorkfield
    Power:95W
    Socket: LGA775
    Cooling: Liquid Cooled
    NVIDIAGeForce GTX 280 SC graphics card
    Features:
    1 GB of onboard memory
    Full Microsoft DirectX 10
    NVIDIA 2-way and 3-way SLI Ready
    NVIDIA PureVideo HD technology
    NVIDIA PhysX Ready
    NVIDI CUDA technology
    PCI Express 2.0 support
    Dual-link HDCP
    OpenGL 2.1 Capaple
    Output: DVI (2 dual-link), HDTV
    Western Digital
    2 WD VelociRaptor 300 GB SATA Hard Drives configured as Raid 0
    Features:
    10,000 RPM, 3 Gb/sec transfer rate
    RAM Memory , Corsair 4 GB (2 x 2 GB) 1333 MHz DDR3
    p/n: TW3X4G1333C9DHX G
    product: CM3X2048-1333C9DHX
    Features:
    XMS3 DHX Dual-Path 'heat xchange'
    2048 x 2 MB
    1333 MHz
    Latency 9-9-9-24-2T
    1.6V ver3.2

  • Ideapad A1-07 tablet wifi-bluet​ooth does not work!

    Hello everyone. As you can see from the title on my tablet is not working wifi and bluetooth. When turning wifi tablet is reset and continues to be off and on until it forcibly turns off, and when you turn it on again, and do not touch wifi everything is normal and there are no problems with resetting. Can someone help me and give suggestion to solve this stupid problem.  I'm from Croatia and I'm bad with the English writing.

    Hi
    Welcome To Lenovo Community
    Please perform a  factory reset 
    Please ensure you have backed any important data before doing factory reset
    Hold the volume down and the power till Lenovo logo appears .
    System will boot into recover mode. Follow the instructions
    Hope This Helps
    Cheers!!!
    Important Note: If you need help, post your question in the forum, and include your system type, model number and OS. Do not post your serial number.
    Did someone help you today? Press the star on the left to thank them with Kudos!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"!  This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • Polygonal lasso tool not working with stylus on Surface Pro 2

    Hi guys,
    I'm new here so please bare with me if I'm posting in the wrong place or don't make immediate sense.
    Hardeware / software used: surface pro 2 and I'm running photoshop CS5.
    Problem is a fairly basic one: I am trying to make basic selections using the polygonal lasso tool (using the stylus that comes with the tablet) but it simply will not work. All I get when I touch the stylus to the screen is the circle that appears then fades. If I attach the keypad and try using that then it works no problem at all.
    Does anyone have any ideas as to whether there is a particular setting that I need to switch on or off e.g. something relating to pressure sensitivity (although not sure why this would affect this particular selection tool)?
    I've searched the web and come up with nothing so far so any help is greatly appreciated!
    Thanks for your time
    Scott

    same problem on surface pro 3 !!!!
    and i think quite significant, for lot of artists using polygonal lasso a lot (including me). How come that the stupid surface cannot work properly

  • Excite PRO 3G connection not work after Android v4.3 update

    Hello,
    I live in Italy and on last Sunday (january 26th) my Excite PRO tablet (model AT10LE-A-10H) got the Android version 4.3.201121220.35.
    After restart my wifi works fine, all other app work fine, but my 3g connection doesn't work, mobile network bar is empty and it says "no service".
    My sim card is ok. I used this sim card before the system update and I didn't get any problem with Android 4.2.2.
    Please help me.
    Thank you

    >After restart my wifi works fine, all other app work fine, but my 3g connection doesn't work, mobile network bar is empty and it says "no service".
    Go to the mobile network settings and search again for the 3G network.
    I had similar problem with my Android Smartphone and my o2 provider
    I started new search, then I chosen the O2 again and then I could solve the problem.
    In case this does not work for you, recommend you to reset the tablet back to default (factory settings)

Maybe you are looking for

  • Problem while loading Crystal report

    Hi all     I'm Harinathan. I'm developing vb.net application with crystal report.

  • Macbook air freezes with spinning wheel

    So, my Macbook Air has suddenly started to freeze and leave me with the dreaded spinning wheel of death. Sometimes I get 10mins into a session, and sometimes the freezing will occur as soon as I log in. I have tried to log in in safe mode, but I also

  • Connecting the iPhone to a laptop

    I have now downloaded iTunes (the latest version) to my laptop, but have not entered my account info or anything to it, just some CD's that were on my hard drive from Windows Media Center. What would happen if I were to connect either my iPod or iPho

  • My mac gone very very slow please help

    Today i was doing my photoshops editing and setdenlly my mac freze and i need to restart and when i restart my mac gone slower than befor

  • Airport Express connecting to xbox360 unable to get IP address

    I am hoping someone can assist with this. Currently I have my Comcast Cable going to a uplink port on a NetGear Hub and then from the Hub i have hardwire connections going to the AE and the Xbox. All computers on this setup get an IP fine but the Xbo