Repaint problem. Paint two components at different times.

I have two labels on a panel. I want to paint them one by one after some action. However, I found that even I call the repaint method of the first label and after some time call the repaint method of the second label, stilll they change at the same time. The first label will wait until the second label repaints.
Below is my code:
import java.awt.event.*;
import javax.swing.*;
public class PaintTest extends JPanel {
     JButton paintButton = new JButton("paint");
     JLabel labelOne = new JLabel("Paint first");
     JLabel labelTwo = new JLabel("Paint second");
     public PaintTest() {
          add (paintButton);
          add (labelOne);
          add (labelTwo);
          paintButton.addActionListener(new ActionListener() {
               public void actionPerformed (ActionEvent evt) {
                    paintButton_actionPerformed (evt);               
     void paintButton_actionPerformed(ActionEvent evt) {
          labelOne.setText("first");
          labelOne.repaint();
          labelOne.revalidate();
          this.repaint();
          this.revalidate();          
          // wait for some time.
          for (long i = 0; i < 99999999; i++) {
          labelTwo.setText("second");
          labelTwo.repaint();
     public static void main(String[] args) {
          JFrame f = new JFrame();
          f.setContentPane(new PaintTest());
          f.pack();
          f.show();
}

The reason its not being updated is because ur not realeasing ur current thread, ur making it work - the time it waits is actually working, so ur not allowing the painting thread to cut in and do the painting. Try this instead:
Implement runnable with:
public void run() {
for (long i = 0; i < 99999999; i++) {}
     labelTwo.setText("second");
     labelTwo.repaint();
     repaint();
     revalidate();
}and in ur actionPerformed:
labelOne.setText("first");
labelOne.repaint();
labelOne.revalidate();
repaint();
revalidate();
SwingUtilities.invokeLater(this);This will give the paiting thread time to repaint before u do u waiting-work....
Stig.

Similar Messages

  • One parameters should pass two Infotypes at different times

    I have two Infotype 0014 & 0015 which needs to be passed to the Class Z_CUSTOM_CLASS method CHECK_EGLIBILITY, Can any body help me in passing these Infotypes at different times but only through One Parameter ( IMPORTING or changing ) .
    I need to know the TYPE or LIKE or Type Ref to for that Par1 ?
    I dont want to specify two parameters each defined based on the structure of P0014 or P0015.
    Z_CUSTOM_CLASS => CHeck_ELIGIBILITY
    importing
    par 1  = 0014
    or 
    Z_CUSTOM_CLASS => CHeck_ELIGIBILITY
    importing
    par 1  = 0015
    the class should be able to process both infotypes, the developer who uses this method would be given Privilege whether to pass 14 infotype or infotype 15 depending on situation.
    it would be of great help if you can show some sample code.

    You can use PRELP structure to type this parameter. This would work similary to customer exits ZXPADU01/02
    data p0014 type p0014.
    data innnn type prelp.
    "before passing to method cast it to PRELP structure
    CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PNNNN_TO_PRELP
    EXPORTING
    PNNNN = p0014
    IMPORTING
    PRELP = INNNN.
    "then pass it to method
    Z_CUSTOM_CLASS => CHeck_ELIGIBILITY
    importing
    par 1 = innnn.  "type PRELP
    "in method cast it back to either p0014 or p0015
    data: p0015 type p0015,
             p0014 type p0014.
    case innnn-infty.
    when '0014'.
       CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
         EXPORTING
           PRELP = INNNN
        IMPORTING
          PNNNN = p0014.
       "your coding here
      when '0015'.
       CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
         EXPORTING
           PRELP = INNNN
        IMPORTING
          PNNNN = p0015.
       "your coding here
    endcase.
    Regards
    Marcin

  • Problem in updating value at different time interval

    Hello,
    Can anyonce suggest me how to update different value at different time interval.
    I want to use only one while loop but I should be able to send data at different rate.
    Eg:- I have 3 input ,10,20,30
    I need to give output 10 at every 5 ms
    20 at every 10th sec
    30th at every 13th sec.
    so my output should be
    10 at 5th sec
    10 at 10 sec
    20 at 10th sec
    30th at 13th sec.
    Please let me know if anyone has solution for it.

    Is this under windows on in a realtime system?
    In the varous posts, you are sometimes talking about milliseconds, sometimes about seconds
    You could run a timed loop at 5ms time and use quotient and remainder for each multiple with three parallel case structures.
    Here's a possible solution for the case:
    output 10 at every 5 ms
    20 at every 10th sec
    30th at every 13th sec.
    as in the original post...
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    VariousTimes.png ‏8 KB

  • How to Link two Facts with Different Time Granularity (Year, Quarter) to a Single Time Dimension

    Hello All,
    I have the below scenario where i have Two Facts Fact Quarterly and Fact Yearly but one Time Dimension which has Quarter grain.
    So my question is how do i Establish relationship from Fact Yearly to Time Dimension??
    Ex: 

    Hi naveej,
    According to your description, you want to know how to build the relationship with time dimension and fact tables. Right?
    Based on your screenshot, it's better to have only one fact table for sales and build the relationship with time dimension. To determine quarterly or yearly data only depends on how you slice the time dimension. However, I notice that the Revenue for year
    is different from the aggregated Profit for quarters. If the Revenue and Profit are different measure, you need to have two fact tables. And you should build the relationship (Regular) between TimeDim and FactYearly on YYYY attribute.
    Reference:
    Defining a Fact Relationship
    Best Regards,
    Simon Hou
    TechNet Community Support

  • Synchroniz​e two waveforms with different time

    Hi All,
         Thank you again in advance for you help on this. I am trying to create a setup where a spectrum is generated over time (millisecond time range, this function works properly), and a maximum for a peak that I select (this also works correctly) plots over time (minute time scale). However, when I try to run this, the fast plot is operating at about 40 Hz, and I have a calculation to allow a resolution feature for the minute time graph (the fast experiment is averaged a given number of times to produce a spectrum which is then analyzed for the maximum peak, so for example, at 40 Hz, and a resolution of 0.5 seconds, it should need to average 20 spectra for each point), but in operation, the time does not work correctly. At 20 spectra averaged per point, I only get about one point per second, not 2. So, in an attempt to correct this, I cut the averages in half, and was able to get it to work at very nearly 2 spectra per second. However, the time is not exact when compared to an external clock, and I need to know then exact time. Thus, is there any way to have the minute time frame graph count time on its own, and just plot a Y value whenever it recieves one? I need to have it plot in real time, as is currently achieved in the attached vi. In th attached VI, I am working with the "chromatography mode" tab, the other tabs already work correctly. However, I am somewhat new at this, and my code is a bit messy, so I apologize for that in advance. Thank you,
    <>< Eric
    Attachments:
    IMS Software v5.4.vi ‏158 KB

    Hello Eric,
    I see that you are creating a waveform using the Build Waveform VI and then wiring it to the outputs in the Chromatography Mode tab - namely 'Waveform Graph' and 'Waveform Graph 3'. Is the 'dt' value constant for every iteration of the while loop? If so, your output should have constant time spacing between plotted values in the waveform graph.
    So, again I am not completely sure what you mean by the IMS not operating at the frequency you input :-(. Are you seeing the problem in 'Waveform Graph' or 'Waveform Graph 3' or both? An simple example VI would be great to describe your issue.
    Vivek Nath
    National Instruments
    Applications Engineer
    Machine Vision

  • How to create an event in two different time zones?

    Hello,
    I am traveling a lot and I would like to be able to enter the flight details in iCal - whether on my iPhone, iCloud, i... whatever. The problem is that I cannot manage to enter these details without calculating the time difference. Example:
    I am flying on Saturday from Frankfurt to Japan. My flight takes off at 19:00h local German time and arrives in Tokyo at 13:00h local time (in Japan)
    I can either specify the time zone for Germany or for Tokyo, but is there a way to enter the event from 19:00h German time to 13:00h Tokyo time?
    Thank you very much for your time.
    Larry

    Hi Alex,
    this applies only when the event takes place in one time zone, but in my case I start the event on one time zone and ends in a different time zone. As it is known, the airlines show always the local times on the ticket. Which means that I start my travel at 19:00h German time (UTC +2) and end it at 13:00h Tokyo time (UTC +9). When I create the event I can choose From Date/Time... To Date/Time and below I have Time zone. Ideally I should have two time zones, one for the start and another for the end.
    Since this situation only applies to travelling (I can't think of another case right now), I believe that Apple didn't take this into consideration.
    Any other thoughts/ideas? Other than manually calculating the difference, of course.

  • I am having problems copying and pasting clips from one project timeline to another. When I do this they often alter in length. Sometimes by two frames. Other times they lose a chunk off the end of the last clip in the sequence. Has anyone else found

    I am having problems copying and pasting clips from one project timeline to another. When I do this they often alter in length. Sometimes by two frames. Other times they lose a chunk off the end of the last clip in the sequence. Has anyone else found this?

    You need to give a lot more information about the media specifications and the project properties you're using in the different projects.

  • Different times on two iPhones 4s

    My wife and I have two iPhone 4s' on Verizon.  We live in Phoenix, which never moves its time.  Our phones each show a different time.  Aren't the times linked to the cell towers?  Any idea as to what gives.

    Try restore from backuo using iTunes.
    If no joy, restore as new without the backupand sync manually
    If the problem persist, talk to you carrier.

  • Duplicate entries in two different time zones

    Somehow iCal imported files (or converted files) into two different time zones--the zone I'm in this year (Asia) and the original zone of the event (US east coast). So I might have an event correctly scheduled at 2pm, April 5, 2001 and a duplicate "false" event scheduled at 1am, April 6, 2001. I now have thousands of such entries, too many to delete manually. It's too late, now that I've made many updates before discovering the problem (all of the duplicate events took place before I moved to Asia), to start over.
    I've turned off "time zone support" since I suspect it was the source of the problem in the first place (I regret ever turning it on).
    I've been able to delete 1500 duplicate "all day" events using a script from John M, but timed events are not identical and therefore can't be uncovered with his script.
    Is there any solution to this problem?

    I never found a solution to this problem

  • Automatic Deployment Rule - One ADR for Two Different Collection for Two Different time Intervals

    I have a scenario where two collection of Windows 8.1 is made based on geographical location. One collection is for all the windows 8.1 machines in India and one collection is for all windows 8.1 machines in US. Now I have created one ADR to be deployed
    to the Collection for Machines in India with a schedule.
    My requirement is that can i use the same ADR for those two collection with different schedule. Say I want ADR to be deployed in India at say 10:PM IST and for US collection at say 10:00 PM PST.
    Can I use one ADR with two different schedule and can be deployed to two different collection. Any help will be greatly appreciated.
      

    Couple of "bits" to help you one your patch automation quest:
    A ADR is very much a 1:1:1 rule.  It creates (or updates) ONE update group, deploys it to ONE collection, and you can provide ONE schedule.  While you are more than capable of flipping said deployment time to use local time instead of UTC, in general
    it's a very simple set of rules that are dogmatically run.
    That said because of the "include" feature of collections it's not that hard to setup a good/robust patching pattern.  What I recommend doing is building an ADR for each variance of deployment of patches or enforcement time.  for example,
    my ADRs look something like this:
    Software Updates - Zero day enforced
    Software Updates - Critical and Security 1 month enforced
    Software Updates - Critical and Security 1 month no reboots
    Exact terminology is up to you of course, but I find a good descriptive ADR name saves a lot of confusion.  For each ADR I create an identical collection.  From there I can use existing collections and a simple "include collection" rule
    to bundle things up and make them part of the patching schedule of my choice.  Anyone can now go into my "software update" folder, look at my collections, and know exactly what gets patched by what deadline.
    Finally, don't be afraid to look into maintenance windows to trim down ADR count.  Making a deployment available for a month before it goes enforced, then setting up groups of maintenance windows (one for each Friday of the week for example) can also
    accomplish a similar goal by having machines auto-patch during their week but you only using one ADR.
    So by having two "types" of collections to manage your patching (one to assign a ADR built by deployment deadlines, the other for exact update windows) you should be able to group most your workstations into a decent patch scheudle without being
    too excessive about creating a billion ADRs.

  • I created a book on iPhoto. I click on the buy button, and I get a connecting message with a blue striped rectangle. I am connected to the internet and I have made books before without any problems. I have tried for the past two weeks at various times.

    I created a book on iPhoto. I click on the buy button, and I get a  message that says Connecting with a moving blue striped rectangle. I am connected to the internet and I have made books before without any problems. I have tried for the past two weeks at various times and I get this same message each time. Any ideas about what is going on? 

    First confirm that you can create a PDF file of your book as described in this Apple document: iPhoto '11: Preview a book, card, or calendar before you order or print it. Post back with the results.
    OT

  • I have "chatted" with customer service 5 different times. I was sent here. I have activated Photoshop Elements 9 on two different iMacs. They are both dead and I am unable to get it to activate on my newest computer. iMac. Can anybody help me?

    I have "chatted" with customer service 5 different times. I was sent here. I have activated Photoshop Elements 9 on two different iMacs. They are both dead and I am unable to get it to activate on my newest computer. iMac. Can anybody help me?

    Unfortunately, only adobe can help you with that, as most people here are just posters such as your self and don't work for adobe.
    If you go here and use the Chat now button (bottom of page), they should get you up and running by resetting your activations.
    http://helpx.adobe.com/x-productkb/policy-pricing/activation-deactivation-products.html

  • How do i run two threads with different sleep times?

    How do i run two threads with different sleep times?
    Ive got thread A and thread B, they both update a jpanel.
    They both start when i press the start button.
    However thread A updates every 250ms and thread B updates every 1000ms. i cant just run them both at 250ms becuase this will mess it up.
    So for every four runs of thread A i want thread b to only be run once
    Does anyone know how to do this?
    Thanks, Ant...

    ok, ive done it but now i cant stop it!
    ive added buttons to start and stop, the start button works but the stop button doesnt. why doesnt "t.stop();" work?
        public void run() {
            while(t == Thread.currentThread()) {
                System.out.println("No " + t.getName());
                if (t.getName().equals("1")){
                    try {
                        t.sleep(1000); // in milliseconds
                    } catch (InterruptedException e) {}
                } else{
                    try {
                        t.sleep(250); // in milliseconds
                    } catch (InterruptedException e) {}
        }

  • Publishing Two Different Sites at Two Different Times

    OK, I want to be able to publish my podcast made through iWeb and my blog page made through iWeb at two different times. Basically, I am waiting for a few things to happen before I want to start my podcast and before that happens I want to update my blog. How do you make this happen? I'm using iWeb 08. Thanks a lot!

    OK, I want to be able to publish my podcast made through iWeb and my blog page made through iWeb at two different times. Basically, I am waiting for a few things to happen before I want to start my podcast and before that happens I want to update my blog. How do you make this happen? I'm using iWeb 08. Thanks a lot!

  • TWO VERY TOUGH SUPPORT PROBLEMS FACED AND SOLVED IN REAL TIME

    pls any body post two very tough support problems faced and solved in real time.
    my id is: [email protected]

    Hi Priya.,
    For example client wants his customer legacy number in XD01 master data which is not there in Standard SAP.we can satisfy the requirement with USER EXIT
    2) If the client wants customer Phone number in the sales order we can use user exit to satify the requirement
    These are not provided in Standard SAP & we should work out on alternative way
    REWARD if helpfull
    Thanks & Regards
    Narayana

Maybe you are looking for

  • When i open iPhoto, it shows my iPod touch is connected even though it's not.

    When I open iPhoto, it shows that my iPod touch 4th generation is connected under the devices tab even though it is not.  Here is a screen shot of what it looks like. Then when I plug in my iPod, iPhoto still will not open, i still get the same scree

  • Can iphone receive audio bluetooth?

    As we all know, the iPhone can TRANSMIT audio via bluetooth, but is it possible for the iPhone to also RECEIVE audio?  Particularly from a TV or computer (assuming they also have BT)?  Reason I ask is that I was looking into buying bluetooth headphon

  • GTX 570 4GB or GTX 770 2GB?

    Which graphics card would be better for After Effects? I know it might obviously be the 770, but would the extra 2GB memory on the 570 not come in handy?

  • IPod Mini error (Delayed write failed)

    Whenever I update songs to my ipod mini it copys about 43 songs until a delayed write failed error message shows up. I'm not able to copy more songs. Any help would be appreciated.

  • Can I sell old versions of photoshop?

    Is it possible to sell old versions of photoshop I've purchased over the years? I'm assuming I'd need to notify Adobe regarding license #, etc..