Paint JProgressBar in new Thread

Hi,
I have a DnD Applet for managing your computer(files and folders) at work from home and have a problem with painting a JProgressBar during the drop action. I've tried to paint the JProgressBar in a new Thread but it freezes. I can see the progressbar but it doesn't move.
I can't do the other things that I wan't to do in drop in a new Thread because of other circumstances so I have to paint the progressbar in a separate thread. Why doesn't the progressbar move?
Any ideas?
public void drop(final DropTargetDropEvent dtde) {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
Thread t = new Thread() {
public void run() {
paintThread(); // THIS IS WHERE I PAINT THE PROGRESSBAR
t.start();
// HERE FOLLOWS THE OTHER THINGS I WANT TO DO IN DROP...
Isn't threads supposed to work side by side?

What you're trying to do is making a myThread method that extends Thread. It's not possible to make a method inherit from anything.
You can't make a class with void either, a class doesn't return anything. You have mixed a class declaration and a method declaration. It doesn't make any sense at all...sorry!
And I don't think you have got the idea with synchronized and what that means...

Similar Messages

  • JProgressBar is not updating even in new Thread !

    Hello every buddy....
    I'm new to SDN and I hope I'll enjoy being an active member.
    I've a problem with updating JProgressBar in actionPerformed method. I know that GUI can not be updating in the event dispatching thread, so, I created a new class to show the JProgress bar in a separate thread as follows:
    {color:#333399}import javax.swing.JProgressBar;
    import javax.swing.Frame;
    public class ProgressBar
    public ProgressBar()
    new Thread(new Runnable()
    public void run()
    showProgressBar();
    }).start();
    }// End of constructor
    private void showProgressBar()
    JProgressBar pb = new JProgressBar(0, 100);
    pb.setPainted(true);
    JFrame f = new Frame();
    f.setSize(250, 100);
    f.getContentPane().add(pb);
    f.setVisible(true);
    while( Crypt.done == false)
    pb.setValue( Crypt.percentageCompleted );
    f.dispose();
    f = null;
    }// End of showProgressBar method
    } // End of ProgressBar class
    {color}{color:#000000}I create an objmect of the above class inside another class called Crypt. when a button is clicked actionPerformed is invoked I do:
    ProgressBar progress = new ProgressBar();
    the frame f shows, but the JProgressBar never shows!
    Can anyone help me?
    with best wishes{color}

    scphan wrote:
    your declaration worked when i plugged it in into my program
    but the way you've programmed the JProgressBar to update is very inefficient, you should just get a ref to your JProgressBar and call setValue() from inside the loop of whatever you're doing
    Edited by: scphan on Mar 24, 2009 10:04 AMThat's bad advice. The setValue method must be invoked on the EDT. I suggest using a SwingWorker and its progress bound property:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html]

  • A New Thread With Each Mouse Click

    Dear Java Programmers,
    The following code gives a bouncing ball inside of a panel. With each click, I need to have a different ball added and the previous ball to keep on bouncing. This part is a larger question of multitreading. When I have an action listener for mouse clicks, and I need to have a new thread with each click, how do I do this and where do I put it?
    Thank you in advance.
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.*;
    import java.awt.Color;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class Multiball extends JPanel implements Runnable, MouseListener {
    Thread blueBall;
    boolean xUp, yUp;
    int x= -10, y= -10, xDx, yDy;
    public Multiball()
    xUp = false;
    yUp = false;
    xDx = 1;
    yDy = 1;
    addMouseListener( this );
    public void mousePressed( MouseEvent e )
    x = e.getX();
    y = e.getY();
    blueBall = new Thread( this );
    blueBall.start();
    public void paint( Graphics g )
    super.paint( g );
    g.setColor( Color.blue );
    g.fillOval( x, y, 10, 10 );
    public void run()
    while ( true ) {
    try {
    blueBall.sleep( 10 );
    catch ( Exception e ) {
    System.err.println( "Exception: " + e.toString() );
    if ( xUp == true )
    x += xDx;
    else
    x -= xDx;
    if ( yUp == true )
    y += yDy;
    else
    y -= yDy;
    if ( y <= 0 ) {
    yUp = true;
    yDy = ( int ) ( Math.random() * 1 + 2 );
    else if ( y >= 183 ) {
    yDy = ( int ) ( Math.random() * 1 + 2 );
    yUp = false;
    if ( x <= 0 ) {
    xUp = true;
    xDx = ( int ) ( Math.random() * 1 + 2 );
    else if ( x >= 220 ) {
    xUp = false;
    xDx = ( int ) ( Math.random() * 1 + 2 );
    repaint();
    public void mouseExited( MouseEvent e ) {}
    public void mouseClicked( MouseEvent e ) {}
    public void mouseReleased( MouseEvent e ) {}
    public void mouseEntered( MouseEvent e ) {}
    public static void main(String args[])
    JFrame a = new JFrame("Ball Bounce");
    a.add(new Multiball(), BorderLayout.CENTER);
    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a.setSize(240,230);
    a.setVisible(true);
    }

    Thank you very much for your replies. As for the multithreading, I have created 20 threads in the main method. With each click, one of these 20 threads starts in order. Now, how do I get a ball to paint with each one? How do I reference them in the paintComponent method?
       public void mousePressed( MouseEvent e )
             x = e.getX();
             y = e.getY();
             blueBall = new Thread( this );
             blueBall.start();
             count ++;
             System.out.print ("count is " + count);
          MyThread[] threads = new MyThread[20];
                for ( int ball = 0;ball < count; ball ++){
                threads[ball] = new MyThread ("" + ball);
                threads[ball].start ();
       }

  • Paintin in new thread

    Hi
    I use a 3rd party product (a component in my GUI) that has a problem painting its components. The paint takes a long time. This freezes the whole application. I thought putting the paint call in the parent class that contains the offending component in a new Thread:
    public void paint(Graphics g)
    paintThread = new PaintThread(g);
    SwingUtilities.invokeLater(paintThread);
    public void rePaint(Graphics g)
    super.paint(g);
    private class PaintThread extends Thread
    Graphics graphics = null;
    public PaintThread(Graphics g)
    graphics = g;
    public void run()
    rePaint(graphics);
    This doesn't work, it leaves the component greyed out.
    Any ideas?
    Thanks
    George

    Chances are, unless you call it directly, that the paint(Graphics g) is being called in the Event Dispatch Thread. What you are doing is declaring a new Thread (PaintThread) that is never used as a Thread (never started). Instead, you use it merely as a Runnable whose run() method will be called later in the Event Dispatch Thread (that's what SwingUtilities.invokeLater is about).
    Do you have access to the source code of your third party product? Feel free to post the paint method to see if it really is the bottleneck of your program.
    Next time, please use code tags (see Formatting tips, prior to posting).

  • How to let new thread to access EJB

    I start new thread in Servlet class and I want this thread to call EJB business method but I get following error:
    javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:"
    Probablly because thread has no credentials and so on. I know this concept violates J2EE specs but I don't know how to make timer to call business mathod every N minutes (I use J2EE 1.3 so I can't use Tiemr EJB).
    I suspect that this new thread has no credentials and no role. What happens if I set run-as some role in servlet? As I saw new thread still has no credentials and role.
    Can anyone suggest me how can I set credentials to new thread so it can call EJB business method or how to implement timer service in J2EE 1.3.

    I start new thread in Servlet class and I want this
    thread to call EJB business method but I get
    following error:
    javax.naming.NameNotFoundException: Name comp/env/ejb
    not found in context "java:"It may happen because you'r new thread doesnt have information (JNDI environment) about EJB references.
    Can anyone suggest me how can I set credentials to
    new thread I guess it's server specific.
    so it can call EJB business method or how
    to implement timer service in J2EE 1.3.Don't use EJB reference. Lookup EJB by it's global JNDI name.

  • As Requested New Thread DSL low speeds and drop outs ref: Anthorny Verizon.

    Please see post by Jerrold concerning the form for information requested, I have never been able to fill this out. Note also I had to sign in three times just to access your private letter to me today.
    Here is a summary of problem:
    When my line was first installed line speed was always between 9 to 12 Mps, which is fine for a 15 Mps line, sometimes would even go higher, so line was ok.
    In October 2012 my line speed dropped to about 5 to 7 Mps, I contacted support and repairs were attemped, but did not correct the problem in fact problem became worst.  My line speed dropped to about 2 to 3 Mps.
    Now from October to end of November, all repairs did not correct problem.  I was told by chat tech support that the problem was being worked on and there was an open ticket.
    In December my line speed returned to normal speed was between 9 to about 13 Mps.  No one had contacted me about this so I again contacted chat tech support who said my line had been fixed and there were no open tickets so have a nice day.  I accepted this at face value and accepted that my line was now ok.
    In January 2013, My line speed dropped again to 2 to 3 Mps.  I contacted chat tech support who tested line and put in a repair request.  No one had responded back to me and a week later my line started to drop in and out losing the connection completely.  I again contacted tech support who told me they had no open tickets on my account, they tested line and while we were talking on voice connection my phone started to have heavy static, both my DSL and Phone dropped out at that point.  Tech support called me back and said he was putting a repair request and that my line had problems. That night Tuesday January 29 my Phone and DSL both died, no dial tone on phone and DSL showed only power light on.  Contacted tech support by a friends cell phone and informed them of this, was told ok it would be fixed by open ticket for next day.
    Repair was to be made on Wednesday January 30, no one showed up, called tech support and told repair would be made on Thursday.  Thursday late repair person showed up around 4:30 or 5:00pm, landlord gave access to building.  I did not know they were here at all, when he told me( my landlord) I tested my DSL and found it running at 1.7 Mps or below that.  When I attempted to call tech support found my phone was still dead, no dial tone at all.  Contacted chat tech support who told me ticket was still open and would be fixed by Friday, or Monday.
    On Monday, phone still dead, DSL running at 1.7 Mps contacted chat support who had me take a phone to the junction box outside of building, plugged in two phones to this no dial tone at junction box (both phones work ok checked using a neighbors phone jack)  should note that on the outside of building there are two junction boxes, but one has lock on it so could not use that one.  Anyway told that DSL could not be fixed until phone is repaired.  Tried contacting phone repair and all I get is auto wait then line drops using a neighbors phone and pay phone my is dead.
    Tuesday again contacted chat support now told to bad, until phone is fixed cannot help me ( was'nt that suppose to be done in first repair, fix phone and DSL given both were reported dead).
    So why am I upset well look at history I now sit with No Phone service, DSL running way below what I pay for and a tech support who has said to bad not our problem.  I also do not want to hear that my line does not and cannot support the speed I pay for ( it has shown to support that speed at beginning of install up to October and again in December).
    Well anyway your letter did not say where to start new thread should I do that here, or in open forum?
    Oh, auto phone repair has given me a date for phone service as this Friday, I hope that at least gets done I cannot contact them any other way it seems.
    You may also ref: my thread on ping rates over 600 on long distants calls for any other history, but as per your request here is new thread.  Please note as of today I have No Phone so can only be contacted by email or here.  Untill phone is repaired that's all there is.

    Please go to your profile page for the forum by clicking on your name, and look in the middle towards the bottom where you will find an area titled "My Private Support Cases".
    There you will find a link to the private board where you and the agent may exchange information. This should be checked on a frequent basis as the agent may be waiting for information from you before they can proceed with any actions. Please keep all correspondence regarding your issue in the private support portal.
    If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer that solved your issue as the accepted solution.

  • I am trying to have some LabVIEW code called in a New thread exit when the testStand sequence terminates

    I have a Sequence that launches a sequence in a New Thread that happens to launch some LabVIEW code.  The problem is when the LabVIEW code finishes, it will not close even when the TestStand sequence terminates. Is there a way to tell this LabVIEW code to Exit, I've tried the Quit LabVIEW function, but that causes a C++ RunTime Error.  The LabVIEW code does end though, and it is set in the VI properties to:
    Checked - Show Front Panel When Called
    Checked - Close Afterwardds if originally closed
    The sequence call that the LabVIEW code is launched from has the following options:
    - New Thread
    Unchecked - Automatically wait for the thread to complete at the end of the current sequence
    Unchecked - Initially Suspended
    Unchecked - Use single threaded apartment
    Any clues on this would be appreciated.

    Hi ADL,
    Everything should close correctly if you check the checkbox "Automatically wait for the thread to complete at the end of the current sequence" in the thread settings.
    With it unchecked, I am seeing the behavior you are. 
    Gavin Fox
    Systems Software
    National Instruments

  • I group messaged from my ipad and this has screwed up the way my messages are reveived by my friends (it creates new threads in their phones with my email in place of my contact name) I've stopped messaging from my ipad but the problem remains. Any help?

    I have an iPhone 4S and use the group texting feature ALL THE TIME. I recently updated my iPad to the latest software and made the colossal mistake of continuing my group messaging from my iPad while connected to wifi. Doing this has successfully screwed but every group text thread I am in, to the point where its very hard for those involved in the thread to keep up. When I initially messaged those I was already engaged in text threads with it created a new thread in their phones replacing my name in their phones with my email. At first this was not a big deal but ever since then the people I am messaging have become increasingly frustrated with how my messages come through. If I am messaged in a group text and respond to it, sometimes when I respond it will create an entirely different thread in my recipients phones. So at that point they have to switch threads in order to read what I wrote. The new thread that my phone creates will send the message under my email not my name (related to the contact they have me saved as in their phones). The worst part about it is that there seems to be no rhyme or reason to why or when my phone will send the message as normal or under my email like it did with my iPad. I haven’t messaged from my iPad since these problems immediately began a month ago but the issues still continue. I have tried everything to get this to stop, I’ve turned off my wifi, I’ve had my friends delete the threads that my messages create in their phones. I’ve had them delete my email in their contact lists and nothing has worked. Can you help me? Any info you could provide would be greatly appreciated.
    Note: My phone message no different whatsoever. All the threads have remained the same. The issue is what it is doing to the people that I am messaging.
        Best Regards
             Rick Mulhern
    Message was edited by: Rickapplehelp19

    I have this identical problem.  For a while my group texts didnt show up on my ipad.  Then one day they did, maybe everyone in the group started using the same os version or something.  Ever since my first reply to the group there have been complaints of multiple threads.  I can not find a pattern for when my group text's decide they want to create a new thread. (it doesnt happen every time)  Everyone in the group has deleted the thread, we've all toggled imessage on/off etc.  There still hasn't been a solution.
    Any help would be appreciated.
    Thanks

  • Cannot post new thread in Calendar forum

    I have a question about Oracle Calendar, and I'm trying to post my question in the Calendar forum. But when I click the "Post New Thread" link, I get an error page that says "Error: you do not have permission to view the requested forum or category."
    What am I doing wrong?
    I am signed in as a registered user, not a guest. I originally created this account a few years ago but have not used it in a long time until today.

    How did you get to the forum? Are you trying to post to an archived forum? You may need to use a different forum, perhaps someone can tell which forum to ask such a question, or you can get a clue by searching here (as opposed to google searching). This is a huge site, sometimes it takes a bit of work to find the right place. For me, the google search generally works better, but that may not apply to what you are searching for.

  • Limited subject characters count when creating a new thread in Portal 7.3 forums

    Hello,
    i was wondering if and how you can change the max. characters for the subject when creating a new thread in Portal 7.3 forums.
    It seems like the character count is limited to 75 characters for subjects.
    I didn't find any suitable property, in the forums admin console, for that issue.
    Thanks

    Hi Andrzej,
    Have faced a similar issue in EP 7.01. It was due to the missing Super Admin access - Save was clocking & timing out.
    Upgraded the Admin permissions and this issue was resolved.
    Hope this helps.

  • Same problem -- new thread

    Hello,
    I have been reading through some of the other threads in the forum and it seems I'm having the same freezing problem with my 4th gen iPod, 50 gig, when connecting to Mac. Thought I'd post a new thread since the others are tremendously long and I have not yet found any answers.
    I have been accustomed to listening to the contents of my iPod through iTunes while at work, but one day the songs started skipping around and iTunes started to freeze. Thinking the problem was iTunes, since my iPod was working fine while not connected to the computer, I ignored it and just ejected the iPod. When I connected the iPod to my iBook G4 at home the same thing happened. iTunes froze, Finder froze, and I had to restart the iPod to disconnect it. After I did that the iPod would no longer show up on the desktop or in iTunes on either my iBook or work G4, so I restored it with the very latest iPod updater, thinking it would be a pain to put all my music back in, but it would be worth it in the end.
    Now when I try to add music to the iPod, the iPod itself eventually freezes mid-update, freezes iTunes and also the Finder and I have to start all over again. After restoring it a 4th time I got wise and decided to manually update. I have been adding 3 or 4 playists myself and then disconnecting for a while before reconnecting to add some more. This is a painstaking process, and I'm sure there is something going on here that is not my fault. The iPod has continued to work 100% normally when not connected to a Mac. The trouble seemed to appear out of nowhere, and I don't think it's a HD problem because of the fact that the iPod never freezes when not connected.
    It seems like many people with this gen. iPod are having similar problems, but I'd like to hear if someone thinks I may have done something to precipitate what is going on with my iPod. It's only a little over a year old and I see no reason why I should be having these Mac-connecting problems with it.
    4th Gen 50 gig click wheel   Mac OS X (10.4.6)  

    Turn off the PC.
    Open your MacBook.
    Open Applications > Utilities > AirPort Utility - click Manual Setup
    Click the AirPort Utility menu item in the upper left hand corner of the screen next to the Apple icon
    Click Check for Updates.
    If you have been updating your MacBook, you may already have the latest version of AirPort Utility. If so, you are all set. If you have an update available for AirPort Utility, go ahead and update it.
    Then open AirPort Utility again and click Manual Setup
    Click on the word "Status" to see if there are any messages or updates available for your AirPort Extreme. If yes, go head and update.
    In the future, use the MacBook to access your AirPort Extreme, not the PC.
    There is no need to "start over" unless you want to do everything again.
    Message was edited by: Bob Timmons

  • (New thread) HP SimpleSave md1000h External Hard Drive - Can't Access Files,

    New thread on same old unaswered issues from others.
    My desktop crashed.  It  needs new harddrive.
    I religiously backup my info everyweek on my simplesave md1000h
    However, before I buy a new computer or replace the harddrive on my old computer, I want to at least get my Quicken Checking account info up and running on my wife's  laptop.
    When I plug in the usb for the md1000h into the laptop,
     it recognizes the  hardware is there but, does not show any files.
    I presume my laptop needs the software to run the simple save.
    However, there is nothing out there on the HP site.
    Can anyone confirm that this is the issue...that I need the software...if so, where can I download it from.
    I beleive the softweare came preloaded on the md1000....now I cant access that software....go figure.
    Any help is appreciated.   Thanks.  Greg

    I too have the exact same problem on my HP SimpleSave (sd500a) external hard drive. I got through to WDC, and they apparently support these devices now. They asked me to send them a copy of my purchase receipt in order to extend my warranty in their system in order to help me (ridiculous!!). I sent the scanned copy of the receipt to [email protected], and got an auto-reply that they will get back to me within 1 day. I also went on their website, and they refer to the device in their system as 'ED Caviar Blue EIDE Hard Drive'. It has the same serial number as my product from HP, so I guess they have acquired these products or at least support of them (?). In any case, I'm freaking out because I have tons of family pictures, video and my entire iTunes library on the device. If any one is able to get help for this, please respond. I am desperate to get this resolved.

  • How can I include results of a subsequenc​e, which runs in a new thread, in the main sequence test report

    Hi!
    I', m working with TestStand Version 4.2.1. I have a main sequence, which calkls different subsequences. All these steps are properly reported. One of subsequences runs as "new thread". How can I include its results in common test report of the main sequence?
    I have markes variables of the subsequence as it is requred for test report (it works OK if it is not a new thread). If the the numerical test, which is executed in this subsequence is correct, I get no results at all. If the numeric test failed I get somewhere in the main sequence report a "red message", that test failed whithout any reference to the step or values of vaiables which were not correct.
    I tried an option "On the fly" in the Report Configuration , but haven' got any useful results. What shall I do?
    Best regards
    Solved!
    Go to Solution.

    Hi,
    I tried it but without success:
    1) I got a reference to the Thread as "Locals.Step1=RunState.Thread" for every of 2 steps which start a thread
    2) I put both "Waits" after steps with (and without) threads, at the same place, where they were before
    3) The sequence run OK, but when it came to Wait for Thread 1 it waited for ever, I had to terminate sequence
    Does it mean, that I got a false reference (suppose No - please, have a look at attached pic)?
    Or does it mean, that Waits are badly placed in the sequence (threads are already terminated)? Here is a pic of sequeces calls with Wait after them.
    Regards
    Attachments:
    Thread.JPG ‏34 KB
    SequenceCall.JPG ‏32 KB

  • How to call a sequence in a new thread from C++ dll

    Here is what I am trying to do:
    I implemented a dll that monitors network traffic, and it also supports message handlers that can be triggered when a specific message has been received. Essentially the receipt of a message is like an event causing additional code to be executed. What I need to do is have the message handler in the dll call/execute a sequence (either is the same sequence file that originally called the dll, or in a different sequence file). Also I want the sequence to be executed within the same execution object for the purpose of result collection and report generation. I am expecting the dll to have to launch a new thread to call a sequence because of the asynchronous nature of the message received event.
    There are easier ways to achieve the same result, but one of my goals is to make it easy for a test developer to configure a message handler, by having only one step in their sequence to configure the message handler. I want the rest to be transparent to the user.
    I am unsure about how to implement this feature, so I am asking for any examples, ideas, comments before I start trying things out.

    Assuming that I understand your question correctly, it would seem to be the best way to do this would be to pass the Execution object to the DLL (either through a direct pass of the Execution object or passing the sequence context, from which you can get the Execution).  Then simply call Execution.NewThread, specifying the SequenceFile object (accessible from Engine.GetSequenceFileEx) and then passing the Thread object out as an output.  Your sequence file in which your DLL is called could then simply have a Wait step which is configured to wait on that Thread object.  What happens in this case is that the results are collected for that thread (which is being executed asynchronously) and returned as the results for the Wait step.
    Although you are probably not using LabVIEW, I have attached an example of this in LabVIEW that might be helpful just for seeing the flow.
    Thanks,
    Andy McRorie
    NI R&D
    Attachments:
    thread_test.seq ‏32 KB
    testthread.vi ‏19 KB

  • How can I include the results are coming from a new thread, in the main sequence report?

    Hi,
    I have a main sequence which calls other sequence running in a new thread.
    I cannot see the results (limit test etc.) comming from that sequence.
    Is there any trick to it?
    Andras

    Hi again Andras.
    I got a reply from the technical support. I hope this help you.
    To include in main report the results of your test in another thread you must follow these steps:
    1.- Right click on the sequence call where you create the new thread. In "Specify Module" panel, just right "Run sequence in a new thread" press "Settings" button and disable "Automatically wait for the thread to complete..."
    2.- At the end of your main sequence add a new "synchronization - wait" step. Configure your wait, selecting in the upper ring tab "wait for thread".
    3.- Then select below "specify by sequence call" and pick over your thread name.
    With these changes your main sequence will add the results from your thread to your main sequence report.
    I hope it works for you. (but sadly it doesn't work for me)

Maybe you are looking for

  • My podcasts on itunes are not ordered correctly ... how to fix?

    As you can see in the screenshot above, my uploaded podcasts are not appearing in the order they were uploaded/released but in a seemingly random order ... how can I get the iTunes store to sort them based on release date so that the most recently re

  • Incompatibility with ATI Radeon HD 4870

    Hi, using Aperture 3 Trial (I'm waiting the deliver of full one from AppleStore) with few Canon RAW images I've experienced very often crash of the application and two kernel panic (sad), especially using brush tool like skin smoothing: 0x98c93fc8 :

  • Adobe reader x won't open in xp

    adobe reader x won't open in xp.. I have uninstalled and reloaded it still will not work

  • How to make a alphabetical list of names

    How to create an alphabetical list of names

  • Map's opens then shuts off

    Yes i recently updated to 1.1.3 about a week ago. Maps worked fine, well i am in Atlanta and used my Map's quite a bit on the way here. Well all of a sudden I go to open it and it opens and acts like its going to load then just kinda goes black and g