Problem with painting/threads/ProgressMonitor

Hello,
I'll try to be clear, ask me anything if it isn't. I have two threads, one that downloads some selected webpages, and the other that reads them. In the thread that reads, there is a ProgressMonitor object, which indicate how many webpages have been read.
I created a JUnit test which works as expected. One thread downloads, the other reads and a nice little progress monitor appears and everything works.
I transfered the code (the part of the code starting the thread that reads, which starts the thread that downloads) into the main application. The threads are working and the ProgressMonitor appears, but it does not draw the components (there is no label, progress bar, button etc...). I can't seem to find the problem. I think it is caused by the threads or synchronized methods, I am not sure as I am no expert with threads. Once the threads have finished running, the components of the ProgressMonitor appears. So I guess that the threads are blocking the (re)painting of the application, but I can't figure why. Im using Thread.yield() quite often. Priorities problem ? Here some parts of the code :
JUnit Test code :
     public synchronized void testHarvest() {
          JFrame frame = new JFrame("Super");
          frame.setVisible(true);
          Harvester harvester = new Harvester(
                    frame,
                    new Rule());
          Thread harvest = new Thread(harvester);
          harvest.start();
          try {
               harvest.join();
          } catch (InterruptedException ie) {}
...Main application :
Code:
public class Gui extends JFrame implements ComponentListener {
   private static JFrame mMotherFrame = null;
    public Gui() {
        mMotherFrame = this;
    private class GuiActionRealize {
          public synchronized void getFromWeb() {
               Harvester harvester = new Harvester(
                         mMotherFrame,
                         new Rule());
               Thread harvest = new Thread(harvester);
               harvest.start();               
               try {                    
                    harvest.join();
               } catch (InterruptedException ie) {}
}Harvester :
Code:
public class Harvester implements Runnable {
  private JFrame mMotherFrame;
  private ProgressMonitor mMonitor;
public Harvester(JFrame owner, IRule subjectRule) {
   mMotherFrame = owner;
    public void find() {
    mMonitor = new ProgressMonitor(mMotherFrame, "Downloading from the Internet.", "", 1, mAcceptedURLs.size());
     mMonitor.setMillisToDecideToPopup(0);
     mMonitor.setMillisToPopup(0);
public void run() {
  find();
  mHarvested = harvest();
  mFinished = true;
  Thread.yield();
public List harvest() {
  download = new DownloadThread(this, mAcceptedURLs);
  Thread downthread = new Thread(download);
  downthread.start(); int i = 0;
  while (!mMonitor.isCanceled()) {
      while (download.getDownloadedDocuments().isEmpty()) {
           try {
                   Thread.yield();
                   Thread.sleep(300);
            } catch (InterruptedException ie) {}
       mMonitor.setNote("Downloading decision " + i);
       mMonitor.setProgress(mMonitor.getMinimum()+ ++i);
       } // end while(!cancel)
       download.kill();
       return mHarvested;
}I'm very puzzled by the fact that it worked in the JUnit Case and not in the application.
I can see that the thread that is responsible for drawing components is not doing his job, since that the mother frame (Gui class) is not being repainted while the harvest/download threads are working. That's not the case in the JUnit case, where the frame is being repainted and everything is fine. This is the only place in the application that I'm using threads/runnable objects.
I also tried making the Gui class a thread by implementing the Runnable interface, and creating the run method with only a repaint() statement.
And I tried setting the priority of the harvest thread to the minimum. No luck.
If you need more info/code, let me know, Ill try to give as much info as I can.
Thank you

Why are you painting the values yourself? Why don't you just add the selected values to a JList, or create a container with a GridLayout and add a JLabel with the new text to the container.
Every time you call the paintComponent() method the painting gets done from scratch so you would need to keep a List of selected items and repaint each item every time. Maybe this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=304939]example will give you ideas.

Similar Messages

  • SwingUtilities.paintComponent - problems with painting childs of components

    Maybe this question was mention already but i cant find any answer...
    Thats what could be found in API about method paintComponent in SwingUtilities:
    Paints a component c on an arbitrary graphics g in the specified rectangle, specifying the rectangle's upper left corner and size. The component is reparented to a private container (whose parent becomes p) which prevents c.validate() and c.repaint() calls from propagating up the tree. The intermediate container has no other effect.
    The component should either descend from JComponent or be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by the Component isLightweight method) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...
    So this method perfectly works for simple Java components like JButton / JCheckbox e.t.c.
    But there are problems with painting JScrollBar / JScrollPane (only background of this component appears).
    I tried to understand why this happens and i think the answer is that it has child components that does not draw at all using SwingUtilities.paintComponent()
    (JScrollBar got at least 2 childs - 2 buttons on its both sides for scroll)
    Only parent component appears on graphics - and thats why i see only gray background of scrollbar
    So is there any way to draw something like panel with a few components on it if i have some Graphics2D to paint on and component itself?
    Simple example with JScrollPane:
    JScrollPane pane = new JScrollPane(new JLabel("TEST"));
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    SwingUtilities.paintComponent(g2d, pane, new JPanel(), 0, 0, 200, 200);Edited by: mgarin on Aug 11, 2008 7:48 AM

    Well the thing you advised could work... but this wont be effective, because i call repaint of the area, where Components painted, very often..
    So it will lag like hell when i make 10-20 repaints in a second... (for e.g. when i drag anything i need mass repainting of the area)
    Isnt there any more optimal way to do painting of the sub-components?
    As i understand when any component (even complicated with childs) paints in swing - its paint method calls its child components paint() to show them... can this thing be reproduced to paint such components as JScrollPane?

  • Serious problems with paint method, need major help

    I've got a mjor problem with displaying a BufferedImage Object. My program takes in an image, i call a method on it which creates an ImageObject, imgObj, which contains the following values:
    Image width, called width
    Image height, called height,
    array of 8 bit integers for the ARGB value of each pixel, called int [] imgCol
    I've managed to create a Buffered Image of the form:
    //make a buffered image ready to take the array of pixels
    bufferedImage = new BufferedImage( imgObj.width, imgObj.height, BufferedImage.TYPE_INT_ARGB);
    Then I set the ARGB values in the BufferedImage, by specifying the integer array of pixels, imgCol:
    //set the values in the buffered image using buffered image method
    bufferedImage.setRGB( 0, 0, imgObj.width, imgObj.height, imgObj.imgCol, 0, imgObj.width);
    Then I try to paint it, callling repaint() in the same method as the code above.
    Now when I try the following stuff I get a Null Pointer Exception:
    public void paint(Graphics g){
         paintImage(g);
    public void paintImage(Graphics g){
         Graphics2D ImageGraphic2 = (Graphics2D)g;
         // Draws the buffered image to the screen.
         ImageGraphic2.drawImage(bufferedImage, 0, 0, this);
    Can anyone help me in fixing this problem?

    Here's the full stack trace, can't make heads or tails of what it's about though
    Full thread dump Java HotSpot(TM) Client VM (1.4.1_01-b01 mixed mode):
    "AWT-EventQueue-0" prio=7 tid=0x0ADAB440 nid=0xb38 in Object.wait() [ef5f000..e
    5fd8c]
    at java.lang.Object.wait(Native Method)
    - waiting on <02F78010> (a java.awt.EventQueue)
    at java.lang.Object.wait(Object.java:426)
    at java.awt.EventQueue.getNextEvent(EventQueue.java:333)
    - locked <02F78010> (a java.awt.EventQueue)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchT
    read.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThr
    ad.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    "DestroyJavaVM" prio=5 tid=0x00034DB8 nid=0x5dc waiting on condition [0..7fadc]
    "Java2D Disposer" daemon prio=10 tid=0x0AD4D1F0 nid=0x218 in Object.wait() [ef9
    000..ef9fd8c]
    at java.lang.Object.wait(Native Method)
    - waiting on <02FE9938> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    - locked <02FE9938> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    at sun.java2d.Disposer.run(Disposer.java:97)
    at java.lang.Thread.run(Thread.java:536)
    "AWT-Windows" daemon prio=7 tid=0x0ACB1528 nid=0x63c runnable [aeff000..aeffd8c
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(WToolkit.java:253)
    at java.lang.Thread.run(Thread.java:536)
    "AWT-Shutdown" prio=5 tid=0x0ACB1158 nid=0x480 in Object.wait() [aebf000..aebfd
    c]
    at java.lang.Object.wait(Native Method)
    - waiting on <02FA4990> (a java.lang.Object)
    at java.lang.Object.wait(Object.java:426)
    at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
    - locked <02FA4990> (a java.lang.Object)
    at java.lang.Thread.run(Thread.java:536)
    "Signal Dispatcher" daemon prio=10 tid=0x009E8350 nid=0x788 waiting on conditio
    [0..0]
    "Finalizer" daemon prio=9 tid=0x0003E978 nid=0x3f0 in Object.wait() [ab1f000..a
    1fd8c]
    at java.lang.Object.wait(Native Method)
    - waiting on <02F699B0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    - locked <02F699B0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    "Reference Handler" daemon prio=10 tid=0x0003D548 nid=0x7a4 in Object.wait() [a
    df000..aadfd8c]
    at java.lang.Object.wait(Native Method)
    - waiting on <02F69A18> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:426)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:113)
    - locked <02F69A18> (a java.lang.ref.Reference$Lock)
    "VM Thread" prio=5 tid=0x009E52C0 nid=0x974 runnable
    "VM Periodic Task Thread" prio=10 tid=0x009E7040 nid=0x4e4 waiting on condition

  • Problems with a thread that records dvd on suse linux

    PLEASE HELP
    I am using SuSE linux, and I record dvd+/- RW with the program growisofs.
    By command line on the linux shell, growisofs records normally, but when I try to use the same line cone that I use in the shell in a java thread, it never stops recording, I mean, it records all data, but it apparently does not close the dvd session, for the grenn light on the drive never stops blinking, and I have to stop the proccess manually, because it never releases the dvd drive.
    I use the thread in a large program, but for debugging this I have made a simple program, whose error is the same.
    the code is:
            String s = "/usr/local/bin/growisofs -speed=1 -M /dev/dvdram  -V MIS27 -A growisofs -P MedImServer " +
               " -p MedImServer -sysid Linux -J -R -l -relaxed-filenames -allow-lowercase -allow-multidot  /windows/C/online";
           Process p;
                try {
                    p = Runtime.getRuntime().exec(s);
                    p.waitFor();
                catch (IOException ex) {
                    JOptionPane.showMessageDialog(null,"erro no runtime");
                    System.exit(0);
                catch (InterruptedException ex1) {
                    JOptionPane.showMessageDialog(null,"erro no waitfor");
                    System.exit(0);
                }with JBuilder 9 debug, I realized that it freezes at the moment of "p.waitFor()".
    I thought that it was a problem with the recording software, but it is not: the same command line that I use in the program I have used in the Linux shell and it recorded perfectly. The program does not require any user interaction but the command line I wrote before. The problem with the Java program is that it records all data, but never returns from the process. It's not a problem with the software, for it records perfectly when it's not called within the Java program, so I imagine that it is some funny thing in either the Runtime.getRuntime().exec(...) or the p.wait().
    Better yet:
    Is there a way to record dvds with a java command instead with an exteranal program?
    This would be the heaven...
    IF it is possible, do it require some sun package?
    Thans
    Tiago

    Did you mean like this?
            Process p = null;
            String s = null;
            File f;
            try {
                f = new File(pathtmp);
                f.mkdir();
                if(VERBOSE) Log.info(GRAVA_LOG_MARK + "Pasta " + f.getPath() + " criada");
                for (Iterator iter = estudos.iterator(); iter.hasNext(); ) {
                    HashMap item = (HashMap) iter.next();
                    String id = (String) item.get("id_paciente");
                    String dt_hr = (String) item.get("dt_hr_estudo");
                    String estudo = id + "." + dt_hr;
                    File dir = new File(distriOff.path);
                    String[] arquivos = dir.list(new FiltroInicio(estudo));
                    for (int i = 0; i < arquivos.length; i++) {
                        File src = new File(distriOff.path + arquivos);
    File dest = new File(pathtmp + arquivos[i]);
    try {
    Util.copy(src, dest);
    catch (Throwable ex) {
    Log.error(mensagem + " " + ex);
    prop.enviaMsg(mensagem + " " + ex);
    throw new ExcecaoDistribuicao(ExcecaoDistribuicao.ERRO, mensagem + " " + ex);
    String os = System.getProperty("os.name");
    String modo;
    if(midia.getEspaco_disponivel_midia() == midia.getTamanho_midia()) {
    //primeira gravagco
    modo = "-Z";
    else {
    //gravagco de novas segues
    modo = "-M";
    String speed = "-speed=1";
    String cmd = "/usr/local/bin/growisofs " + speed + " " + modo + " " + dvdDevice + " "
    +" -V " + prop.getIdMidiaAtual() + " -A growisofs -P MedImServer "
    +"-p MedImServer -sysid " + os + " -J -R -l -relaxed-filenames -allow-lowercase -allow-multidot " + pathtmp;
    p = Runtime.getRuntime().exec(cmd);
    p.waitFor();
    catch (IOException ex){
    Log.error(mensagem + " " + ex);
    prop.enviaMsg(mensagem + " " + ex);
    throw new ExcecaoDistribuicao(ExcecaoDistribuicao.ERRO, mensagem + " " + ex);
    catch (InterruptedException ex) {
    Log.error(mensagem + " " + ex);
    prop.enviaMsg(mensagem + " " + ex);
    throw new ExcecaoDistribuicao(ExcecaoDistribuicao.ERRO, mensagem + " " + ex);
    try
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    // Lj saida padrco do comando
    while ( (s = stdInput.readLine()) != null)
    Log.info(GRAVA_LOG_MARK + s);
    catch (IOException ex)
    Log.error(mensagem + " " + ex);
    prop.enviaMsg(mensagem + " " + ex);
    throw new ExcecaoDistribuicao(ExcecaoDistribuicao.ERRO, mensagem + " " + ex);
    try
    BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    // Lj qualquer erro do comando
    while ( (s = stdErr.readLine()) != null) {
    Log.info("Processo de Gravagco: " + s);
    if((s.indexOf("failed") != -1) || (s.indexOf("error") != -1) || (s.indexOf("unable") != -1)) {
    Log.error(mensagem + " " + s);
    prop.enviaMsg(mensagem + " " + s);
    throw new ExcecaoDistribuicao(ExcecaoDistribuicao.ERRO, mensagem + " " + s);
    catch (IOException ex)
    Log.error(mensagem + " " + ex);
    prop.enviaMsg(mensagem + " " + ex);
    throw new ExcecaoDistribuicao(ExcecaoDistribuicao.ERRO, mensagem + " " + ex);
    I tried to execute it, and it indeed doesn't freeze, but it doesn't record a thing either...
    now it doesn't even wait for the thread, which is VERY weird: it does not record a thing!!! It just passes by the line 'p.waitFor()'...
    Any sugestion?
    By the way, thanks for helping me...
    Tiago

  • I have problems with seeing thread posts...

    I got problems with this Forum itself: I can't see the posts of the threads. Just a few times I did see the content of one page but if I will go to the next page, the posts are be hidden again =/

    I was having the same problem.  Emptying the Safari caches and restarting has fixed it - at least for now.

  • A small problem with painter when i try to use color selector

    in paint brush there is this color selector that things that takes drops a dropper i think it's called if i choose it and use it on some part of the pictuer i get this color on paint 1 but i can't use it to change color 2 why is that and what can i do about this?
    thanks in advance.

    in paint brush there is this color selector that things that takes drops a dropper i think it's called if i choose it and use it on some part of the pictuer i get this color on paint 1 but i can't use it to change color 2 why is that and what can i do about this?
    thanks in advance.
    Hi
    1. Select the Color Picker (Eye Dropper).
    2. Click Color 1.
    3. Select a color from the Pallette.
    4. Select Color 2.
    5. Select the second color from the Pallette.
    6. Select a Brush from the Brushes drop down.
    7. When you use the left Mouse Button, you will get Color 1.
    8. When you use the Right Mouse Button, you will get Color 2.
    While you are painting, you can select the Color Picker at any time to change either color 1 or 2.
    Windows 7 features - Paint - Microsoft Windows
    Getting started with Paint
    Using Paint
    Hope this helps.
    Thank You for using Windows 7
    Ronnie Vernon MVP

  • Problem with multiple threads accessing the same Image

    I'm trying to draw into one Image from multiple threads. It works fine for a while, but then suddenly, the image stops updating. Threads are still running but the image won't update. I'm using doublebuffering and threads are simply drawing counters into Image with different speed.
    It seems like the Image gets deadlocked or something. Anyone have any idea what's behind this behavior or perhaps better solution to do such thing.
    Any help will be appreciated.

    Sorry Kglad, I didn't mean to be rude. With "No coding
    errors" I meant the animation itself runs with no errors. I'm sure
    you could run the 20 instances with no freezing (that's why I put
    the post :) ) But I'm affraid it is an animation for a client, so I
    cannot distribute the code.
    Perhaps I didnt explain the situation clearly enough (in part
    because of my poor english...).-
    - By 20 instances I mean 20 separated embedded objects in the
    html
    - The animation is relatively simple. A turned on candle, in
    each cycle I calculate the next position of the flame (that
    oscilates from left to right). The flame is composed by 4
    concentric gradients. There is NO loops, only an 'onEnterFrame'
    function refreshing the flame each time.
    - It's true that I got plenty variables at the _root level.
    If that could be the problem, how can I workaround it?
    - It is my first time trying to embed so many objects at the
    same time too. No idea if the problem could be the way I embed the
    object from the html :(
    - The only thing I can guess is that when a cycle of one of
    the object is running, the other 19 objects must wait their turn.
    That would explain why the more instances I run, the worst results
    I get. In that case, I wonder if there's a way to run them in a
    kind of asynchronous mode, just guessing...
    Any other comment would be appreciated. Anyway, thanks a lot
    everybody for your colaboration.

  • Problems with java Thread

    I'm reading book "JAVA THREAD" published by OREILLY.
    And on fifth chapter, it gives an example.
    one Thread's two method:
    private boolean done = false;
    public void run()
    while(!done)
    foo();
    public void setDone()
    done = true;
    it says, the run method will be compiled as machine code:
    Begin method run
    load register r1 with memory location 0xff12345
    Label L1:
    Test if register r1 == 1
    If true branch to L2
    Call method foo
    Branch to L1
    Label L2:
    End method run
    setDone method will be compiled like:
    Begin method setDone
    Store 1 into memory location 0xff12345
    End method setDone
    And it says " because Run method will never reload 0xff12345 to register r1(in while loop), so setDone method will never lead to run stop.
    I'm so puzzled with this. I have test this code on windows platform, run method can stop after another Thread call setDone method !.
    but I think "JAVA THREAD" should have error on this, so why ?

    If the book says it will happen like that, then the book is wrong.
    I think what they meant--and what would be correct to say--is that that is an example of what could happen if you don't synchronize all access to the run variable.
    The point is this: Threads can have local copies of variables, that are separate from other threads' local copies and separate from the "master" copy. The spec doesn't define where those local copies live--the implementation can put them anywhere it wants--but the most natural and sensible thing would be to store the local copies in CPU registers, rather than in main mem.
    The example the book gave shows what might happen if that VM stores threads' local copies in registers. There's no guarantee that the problem they described will happen, but it could, so you have to guard against it.
    You guard against it by declaring that shared variable volatile, which requires that the threads use the master copy rather than their local copies, or by synchronizing every access to that thread. Syncing requires reading from the master copy on entering the sync block (or on first access) and writing out to the master copy upon leaving the sync block.

  • Problems with painting

    I am trying to put jlabel(with a picture ) on another jlabel (with a picture) how i could do this... oh i am using ide interface, when i put one on another it always goes near by it but not on it! pls help me! ;)
    tryed many things as painting background then moving on it label but there comes grey color(bakcground color) after moving to another place.
    repaint overloads system or smth like this. well i a can say i am going to panic now :(
    sorry for spaming in many forums but i really need help:(

    audryste wrote:
    sorry for spaming in many forums but i really need help:(Choose one thread and state in the other that it is closed or you will severely limit the help folks will offer you.

  • Problem with Java threads

    Hi,
    I developed a class, which reads some data from an XML file and transports it to a database, using JDBC. The class worked perfectly fine.Then, I used a thread to execute the same class (using the run() method and the usual stuff), but now as soon as the thread exits, Windows says that an illegal memory access has been made.
    Has anybody encountered a similar problem? any help will be appreciated.
    thanx,
    regards.

    What type of driver are you using? If it's the JDBC ODBC bridge or any other driver that uses native libraries then maybe improper resource deallocation could cause the trouble.
    robert

  • PROBLEMS WITH A THREAD!!!

    Hi, guys!
    Posted this in another forum, but no good answers...
    I got a class "GUI" which is calling a method in class FileCopy on a button-click.
    Class GUI calls -------> copy in class FileCopy
    The FileCopy-class looks kinda like this:
    public class FileCopy implements Runnable {
    Thread thread = null;
    public void copy( ...params...) {
    thread = new Thread(this);
    // Asign some vars
    thread.start();
    private void copyFiles(File file, File destination) {
    // Copy the file
    public void run() {
    for (Iteration e = collection.iterator(); e.hasNext();)
    copyFile((File) e.next(), destination);
    // Kill thread next
    The problem is that the thread seems to call the metod copyFiles and then (before the copyFiles-method is done) go to the part in run where I kill the thread. That results in a non-copied file!!!!
    I've tried to use the join-method to get the thread to wait for the copyFiles-method to complete, but then the GUI freezes and that's not an option!!!
    Plz help!!!
    /Andrew

    Hi
    you are already in the event thread (dispatching thread)
    and you don't need to spawn another thread, just handle the event normally
    in your event handler.
    if you really want to use thread use a Timer to copy (set a low interval)
    or
    class FileCopy implements Runnable {
    FileCopy(params...) {
    // Set your file names and params here
    private void copyFiles(File file, File destination) {
    // Copy the file
    public void run() {
    for (Iteration e = collection.iterator(); e.hasNext();) {
    copyFile((File) e.next(), destination);
    // let the thread end normally
    // event handler
    public void actionPerformed(ActionEvent e) {
    Filecopy copy = new FileCopy(params...);
    new Thread(copy).start();
    I hope this helps

  • Problems with paint

    Hallo, I'm trying to create a application with 1 button. When I click the button a oval should be drawn on the screen. But I can't paint from the button handler, so I use Graphics g=getGraphics();
    But when I put an other window in front the oval is gone...
    Should I use something else instead of getGraphics?

    Or you could have the button control a boolean value:
    public class programma extends Frame {
    boolean drawOval = false;
    public void actionPerformed(ActionEvent e) {
      drawOval != drawOval; //I think this works, maybe not
      repaint();
    }Then you would override the paint method adding an if(drawOval):
    public void paintComponent(g) {
      if (drawOval)
        g.drawOval(500,500,200,100);
    Steve                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem with JTimer and ProgressMonitor

    Hi,
    I am developing an JApplet which reads data from database and displays, for this i am using applet servlet communication, now depending upon the intranet speed and file size the time for getting the data varies, so I have to show a the user the process is going on, now i went through this article
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
    I modified some code for my use but it does not work i will cut paste it down here
    Can anyone help me in doing it the right way. should i use JProgressBar instead of ProgressMonitor. is so how???
    //c is the content pane of my applet
    ProgressMonitor pMonitor = new ProgressMonitor( c, "Getting Data...", "Note", 0, 100 );
    pMonitor.setProgress( 0 );
    pMonitor.setMillisToDecideToPopup( 0 );
    pMonitor.setMillisToPopup( 2);
    pMonitor.setMaximum( 20000 );
    timer = new javax.swing.Timer( 100, new TimerListener() );
    counter = 0;
    timer.start();
    // this is the method where i get all the data from database
    getAllData();
    timer.stop();
    public class TimerListener implements ActionListener
    public void actionPerformed( ActionEvent e )
    counter = counter + 1;
    pMonitor.setProgress( counter );
    Ashish

    Is the dialog a modal dialog? This can block other UI updates.
    In general, you should make sure that it isn't modal, and that your workThread has a fairly low priority so that the UI can do its updating

  • Problem with my Thread

    MainProgram
    Thread1->named th does some process
    Thread2->ProgressBar where i have this code
    while(th.isAlive())
    Thread.sleep(4000);
    My program is stuck up in the above loop. Eventhough thread1 and thread2 are independent,thread one is never dead. Once thread2 completes its task thread1 is getting dead. Why this happens.
    In short i want both thread to be executed parallely

    perhaps you should first test your ideas on simple code before implementing them in a real program? So just generate some test code like this:
    public class Test {
         public static void main(String[] args) {
              Thread thread1 = new Thread1();
              Thread thread2 = new Thread2(thread1);
              thread1.start();
              thread2.start();
    class Thread1 extends Thread {
         public void run() {
              System.out.println("Thread 1 started.");
              int count = 3;
              while (count > 0) {
                   System.out.println("Thread 1 goes to sleep.");
                   try {
                        Thread.sleep(2500);
                   } catch (InterruptedException e) {}
                   System.out.println("Thread 1 wakes up.");
                   count--;
              System.out.println("Thread 1 ended.");
    class Thread2 extends Thread {
         Thread watchedThread;
         Thread2(Thread aThread) {
              this.watchedThread = aThread;
         public void run() {
              System.out.println("Thread 2 started.");
              while (this.watchedThread.isAlive()) {
                   System.out.println("Thread 2 goes to sleep.");
                   try {
                        Thread.sleep(1000);
                   } catch (InterruptedException e) {}
                   System.out.println("Thread 2 wakes up.");
              System.out.println("Thread 2 ended.");
    }When you have figured out what you want (and how to do it), only then implement it in a real program.

  • Problems with 'My Threads'

    Hi everybody,
    I understand that it's hard to please everybody, but after the switch back to all threads I started to get Internal Server Error and very slow performance when the list works.
    Is it possible to have an option of how many threads to show (or date filter)? The date filter can default to last 2 months, but it could be changed by a user. Also, default date filter can be configured in the settings.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

    I submitted this as a bug request. Thanks!
    Ed Price, Power BI & SQL Server Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

Maybe you are looking for

  • Display pop ups in the jsp by using Java script

    Hi can any body say ,how to display pop ups in the jsp by using Java script ?

  • RE: My story -Sadly NOT a fairy tale

    can you confirm that you have recieved an email from me entitled the above. It is about my 3 year fight with BT to have my account in My own Name rather than that of my ex-husband and a request for the refund of cancellation charges which I feel were

  • Font Problem: Zebra label print

    Hi, I'm designing label print with Zebra Z4MPlus, I can rotate the text in 90 degree, but the problem is the printed font is so ugly and letters are twisted together, I take the font 'HELVE', it should be all right, how can I solve it?! Any suggestio

  • My computer in my local network

    I recently bought a mac pro and am using an airport extreme base station. I need to access my computer on the local network but somehow I have made it invisible! I think i turned something off but now I need to make it visible again to other computer

  • What is filter daemon in search index engine? Where can I know all that is needed to know about SharePoint search architecture?

    Going through the search architecture, I found something called filter daemon, I tried looking online for more information about it but people have just reported errors of filtering time out etc. What is it and where can I find detailed information a