Trying to Update JLabel inside a ActionEvent

I read that you can't update the UI while inside an ActionEvent ... I have a very small program and think that creating a new thread would be over the top for this. Can anyone offer any other ideas ? Here is the action event listener.
public void actionPerformed(ActionEvent ae)
     String command = ae.getActionCommand();
     if(command.equals("createFile"))
          completedL.setText("Generating spread sheet, please wait..... ");
          completedL.repaint();
          System.out.println(ae.getActionCommand());
          storeNumber=storeNumberF.getText();
          cardNumber= cardQtyF.getText();
          found = info.find(storeNumber);
          if(found != null)
               System.out.println("Found " + found.getStoreNumber());
               storeNumber =found.getStoreNumber();
               System.out.println("Last card # is " + found.getCardNumber());
               cardValue =found.getCardNumber();
          else
               System.out.println("can't find " + storeNumber);//put system dialog box here !!
          h = Integer.parseInt(storeNumber);
          x = Integer.parseInt(cardNumber);
          System.out.println("Store # : " + h +" Card Qty " + x);
          try
               makeSheet(h,x,cardValue);
          catch(IOException ioe)
               System.out.println(ioe);
}Been looking at this for a few days and have tried various things. I'd be willing to give threads a shot, but to me it seems like there should be another way.
-Ben

makesheet() is the one that takes a while. I made the following adjustments and it didn't update the label until the end just like before :
public void actionPerformed(ActionEvent ae)
     String command = ae.getActionCommand();
     if(command.equals("createFile"))
          completedL.setText("Generating spread sheet, please wait..... ");
          completedL.repaint();
          System.out.println(ae.getActionCommand());
          storeNumber=storeNumberF.getText();
          cardNumber= cardQtyF.getText();
          found = info.find(storeNumber);
          if(found != null)
               System.out.println("Found " + found.getStoreNumber());
               storeNumber =found.getStoreNumber();
               System.out.println("Last card # is " + found.getCardNumber());
               cardValue =found.getCardNumber();
          else
               System.out.println("can't find " + storeNumber);//put system dialog box here !!
          h = Integer.parseInt(storeNumber);
          x = Integer.parseInt(cardNumber);
          System.out.println("Store # : " + h +" Card Qty " + x);
     //     try
               Runnable makeSheetRun = new Runnable()
                    public void run()
                         try
                              makeSheet(h,x,cardValue);
                         catch(IOException ioe)
                              System.out.println(ioe);
               SwingUtilities.invokeLater(makeSheetRun);
     //     catch(IOException ioe)
     //          System.out.println(ioe);
}

Similar Messages

  • Trying to get components inside a panel in content pane

    Hello,
    I am trying to update the combo boxes inside a panel with a list of values(list is stored as an array).
    My heirarchy of components is as follows:
    frame-->contentpane-->gamepanel-->combopanel-->combobox
    i am able pass my frame into my code. now i have to get the combobox to update it.
    frame.getcontentpane()this returns to me my contentpane - RIGHT/WRONG???
    if right, after this how do i reach the combopanel and get the combobox such that I am able to write
    combobox.addItem(array)HELP PLEASEEEEEEEEEEEEE
    Thanks,
    Manju

    Be patient. 30 minutes is not a long time to wait for answers, especially on the weekend. Instead of waiting impatiently why don't you try reading sections from the Swing Tutorial. For example, How to Use Combo Boxes:
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
    so how do i keep the reference?Define a class variable for the combo box:
         This works on non editable combo boxes
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ComboBoxAction extends JFrame implements ActionListener
         JComboBox comboBox;
         public ComboBoxAction()
              comboBox = new JComboBox();
              comboBox.addActionListener( this );
              comboBox.addItem( "Item 1" );
              comboBox.addItem( "Item 2" );
              comboBox.addItem( "Item 3" );
              comboBox.addItem( "Item 4" );
              //  This prevents action events from being fired when the
              //  up/down arrow keys are used on the dropdown menu
              comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
              getContentPane().add( comboBox );
         public void actionPerformed(ActionEvent e)
              System.out.println( comboBox.getSelectedItem() );
              //  make sure popup is closed when 'isTableCellEditor' is used
              comboBox.hidePopup();
         public static void main(String[] args)
              final ComboBoxAction frame = new ComboBoxAction();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
    }Even though the combo box is created in the constructor, the actionPerformed() method can still access the combo box because it was defined as a class variable.

  • Update JLabel Immediately

    Hi there,
    I am trying to update my JLabel immediately. I am processing files in a for loop and updating the JLabel as the loop iterates. The problem is that the label in my GUI does not update immediately, but only when the program has finished doing everything else. Is there a way to update the label/panel immediately?
    Thanks

    Hmm... sounds like mixing AWT and swing, which is not recommended, but I could be wrong. Actually I found SwingWorker one of the easier classes to use, I hadn't even looked at the API before I read this thread -- here's a Really Bad Example that takes all its useless time-consuming activity off the EDT using two SwingWorkers -- hope this might get you started...import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.SwingWorker;
    public class ReallyBadExample extends JFrame {
        private JPanel nyPanel;
        private JButton myButton;
        private JLabel myLabel;
        String[] myString = {"One", "Two", "Three", "Four", "Five",
                "Six", "Seven", "Eight", "Nine", "Ten!" };
        int i;
        public ReallyBadExample () {
            setLayout (new GridLayout (0,1));
            setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            myButton = new JButton ("Click");
            myButton.addActionListener (new ActionListener () {
                public void actionPerformed (ActionEvent e) {
                    new CountToTen ().execute ();
            add (myButton);
            myLabel = new JLabel ("Waiting");
            add (myLabel);
            pack ();
            setVisible (true);
        class CountToTen extends SwingWorker<Object, Object> {
            @Override
            public Object doInBackground () {
                for (i = 0; i < 10; i++ ) {
                    new CountOne ().execute ();
                    for (int j = 0; j < 1000000000; j++);
                return null;
        class CountOne extends SwingWorker<String, Object> {
            @Override
            public String doInBackground () {
                return myString;
    @Override
    protected void done () {
    try {
    myLabel.setText (get ());
    } catch (Exception ignore) {
    public static void main (String[] args) {
    SwingUtilities.invokeLater (new Runnable () {
    public void run () {
    try {
    new ReallyBadExample ();
    } catch (Exception ex) {
    ex.printStackTrace ();
    System.exit (1);
    }db

  • Cannot see music playlists when trying to update ipod

    hello, i've had lots of problems with itunes 7, stuttering music, lock ups etc.- wish i hadn't upgraded!
    latest issue is when eventually i updated ipod to 1.2 software and tried to update it i can see playlists for movies and podcasts but not for music.
    any ideas how to solve please.
    i thinks its bad that apple haven't posted at least a note saying they'll look into these issues

    hello again,
    i know i can use the black arrow to view playlists on my ipod, but there arn't any - i did a restore on this ipod and so it hasn't got any playlists on it now, and i want to get them back on, i only did the restore because i was having the same problem when i upgraded to 1.2 as i'm having now and i hoped restore might solve it but it didn't!
    to get playlists back on the ipod i was hoping to open up the music tab on the large ipod menu and select various playlists from the list inside the rectangle as i used to on itunes 6 and the ones before, but the playlists don't show up for me to select to copy to my ipod, the playlists are still in itunes and i can play them on the computer albeit with bad sound quality since upgrade.
    i can see playlists under the movies and podcast tabs and i can copy these to ipod but no music playlists.
    as i've said i can copy playlist the long way by dragging the playlist from the grey list on the side of the screen and dropping them on the ipod under devices but this will take days
    thanks

  • Error message when trying to update my world or anyof my applications

    I receive an error message when trying to update any of my applications.  Example  facebook, my world..etc...
    Error 40820 try later

    Hi and Welcome to the Community!
    While normally it is much more accurate to search with the accurate and complete error message, including all punctuation and error codes, in your case here is a KB that discusses that error:
    KB28188"BlackBerry App World is having trouble connecting to the BlackBerry App World server. Verify your network connections and try again. (Error id: 40820) " error is displayed when opening App World on the BlackBerry smartphone
    Hopefully it contains something useful! There also are multiple existing threads on this site that discuss that exact error...your review of those might prove useful, and a search of this site, using the error message, error code, or symptom, should reveal all applicable existing threads to you.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Error trying to update to v7.1.0.391 (Rogers)

    Hi folks,
    Trying to update the O/S on my 9810.
    All I get is an error screen that says this:
    ! There was an error updating your software
      This BlackBerry Device Software upgrade includes new features and sigificant
      enhancements to the BlackBerry solution and,as such, is only available to users with
      an active BlackBerry subscription. To learn more about BlackBerry service, please
      visit www.blackberry.com/service.
    This is beginning to get a bit frustrating and any help would be greatly appreciated.

    Hello,
    The message is actually completely accurate...but here is more:
    KB19921 Unable to upgrade BlackBerry Device Software because the message "BlackBerry Device Software updates are only available to BlackBerry smartphone users with an active BlackBerry service subscription" appears when Desktop Manager is launched
    If you do not subscribe, from your mobile service provider, to an adequate BB-level data plan, then you are not eligible to use the updated OS levels.
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Trying to update an app but is asking for another account password and the app was purchased with my account and not the want that is asking for the password? Please help!!!

    Im trying to update an app on my phone but keeps asking me for the password of my cousins account, and I have never purchased an app with his account. I restored my cousins phone on my computer but I dont know if that has to do anything with the problem.

    Because that person’s Apple ID was put inside the application when it was downloaded from the iTunes Store.
    (120240)

  • I tried to update Safari for OS 10.7.5 and it no longer works.   What should I do to revive it?

    I tried to update Safari for OS 10.7.5 and it no longer works.   What should I do to revive it?

    Try cleaning the lens and see if that will restore functionality to the DVD drive.  Use a DVD lens cleaning disk, if you have a can of compressed air, shoot some into the slot or wrap a fine microfiber cloth (eyeglasses cleaning cloth)  around a business card and insert it gently inside the slot.
    If no success, make an appointment at an Apple store genius bar and get a free diagnosis from them.
    Ciao.

  • I am trying to update my payment

    I am trying to update my payment for App World. I want to use my Paypal I enter all of my information but I keep getting a error. "We ran into a problem while processing your request. Please try again later. (PS1036lq). Been two days and no issue with my Paypal. Any help or know what that error code means? I had no issues but when I installed the upgrade to App World it wants me to update my payment method.

    Hi and Welcome to the Community!!
    Please double check your PayPal account -- log into it from a PC/browser and ensure that the credentials you use there are identical to those you use to log into MyWorld. Also ensure that all credit cards you have attached to PayPal are current and valid...we have learned that if there is any credit card attached to your PayPal account that is invalid for any reason (e.g., expired), it will prevent AppWorld purchases from completing, even if it is not the funding source. Further, there must be at least one (valid) credit card attached to the PayPal account.
    We also have heard from some users who report that creating a whole new PayPal account somehow fixes things and allows them to make purchases. I'm not sure why that works, but reports exist that it does.
    Also please try a hard reset: With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation. Like all computing devices, BB's suffer from memory leaks and such...with a hard reboot being the best cure.
    Cheers!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • I keep getting an "Update Failed" message when trying to update my apps using Creative Cloud.

    I keep getting an "Update Failed" message when trying to update my apps using Creative Cloud.

    [ Mac 10.9.3 / Indesign CC update fail / Premiere update fail / Adobe Media Encoder 7.2.2 update fail ]
    Adobe Media Encoder was the problem for me. There's no separate uninstaller for AME. My ID CC and Premiere couldn't be updated (for the AME7.2.2 update as the only change). MCMHMPEGVideoCodec.framework seemed to be the factor.
    I uninstalled Premiere (only), after having manually removed MCMHMPEGVideoCodec.framework from inside AME. After boot I installed it again and voilà, both (ID & Premiere) updates went trough fine. The MCMHMPEGVideoCodec.framework was on place inside AME too.

  • Trying to update channels in real time while controlling Agilent 34970a

    Hello all,
    I've gotten such valuable help on these forums and I am hoping that someone will be able to point me in the right direction with this issue. I'm still pretty new to LabVIEW so please bear with me.
    I am working with the LabVIEW driver for the Agilent 34970A connected over a GPIB-ENET 100/1000. The device was detected and works just fine. The reason I am writing today is that I am trying to update the channel list in real time. Currently I need to stop the whole process in order to edit the channel list but due to the nature of the tests we will be performing it is important that I can add more channels as I go without interrupting the testing going on.
    I've searched the forums and tried modifying the channel string control to "Update value while typing," and "Limit to single line." The motivation behind the latter change was so that I could modify the channel list and use the ENTER key to execute. I've also tried creating a while loop with shift registers but the construction ws so clumsy that it did not work either.
    I am pretty sure that the modification should occur right at the string control but cannot be certain since the pint is for it to reinitialize what channels to scan and that occurs further down in the VI. I've attached the VI I am working with; it is an only slightly modified version of the driver's Advanced Scan Example. 
    Thank you all in advance,
    Yusif
    Solved!
    Go to Solution.
    Attachments:
    HP34970A Advanced Scan Example_YN_5-16a-12.vi ‏77 KB

    You may have added a shift register, but you're not actually comparing anything. You need to compare the value of the control to the value of the data coming from the shift register to see if it changed. If so, change the scan list.
    If you need to have a delay after changing the scan list, then you should add the delay inside the case structure that calls the VI to reconfigure the scan list. You can use the Time Delay VI to cause the delay to occur after configuring the scan by using the error wires to force execution order.
    P.S. Your naming scheme for VIs implies that you are probably not using a source code control system. If so, you would be well served in taking the time to learn about source code controls systems and installing one. It's very easy, and there have been numerous threads in the LabVIEW forum on recommendations of source code control systems.
    Attachments:
    changed.png ‏15 KB

  • Update JLabel

    I am just wondering if/how I can update JLabel or do I just have to use another method.
    I just want it to like update words in the JLabel...
    ...is there any actionListener/ItemListener to go with JLabel?
    I have also tried just writting strings directly to the JFrame, but when the JFrame updates, the words just write over each other....is there any way I can clear the JFrame before I redraw the string? (as an alternative to using JLabel?)
    Thanks
    Shellie

    You can make a JTextField look like a JLabel if repainting JLabel
    is a pain...
    final int LABEL_SIZE = 5;
    JTextField tf = new JTextField(LABEL_SIZE);
    tf.setEditable(false);
    tf.setBackground(UIManager.getColor("Label.background"));
    tf.setForeground(UIManager.getColor("Label.foreground"));
    tf.setBorder(UIManager.getBorder("Label.border"));That way you don't have to worry about repainting as
    tf.setText(updateText) will do...
    Also you can make it look like mutiline Label by using HTML in
    the textfield -
    tf.setText("<HTML>text1.....<br>text2....</HTML>");

  • I am trying to update Adobe Bridge and Photoshop CS6, because it is not opening my CR2 files taken by my Canon 6D.  I have tried to go to help updates, and the software says that it is "Up to Date".  However, if I view the plug-in, it says that Camera R

    I am trying to update Adobe Bridge and Photoshop CS6, because it is not opening my CR2 files taken by my Canon 6D.  I have tried to go to help > updates, and the software says that it is "Up to Date".  However, if I view the plug-in, it says that Camera Raw is only version 7.1.  I can not find a direct download for Camera Raw 7.3, only the DNG converter, NOT CAMERA RAW!  Please Help!

    Did you fix your issue?  I am having the same one

  • Hi, I am trying to update an iPhone 4 from iOS 4.3.3 to iOS 7.0.4, and every time I try to update it comes up with an error message saying that there was a problem because the network connection was reset. Is there any way I can get past this and update?

    The full message said:
    There was a problem downloading the software for the iPhone "Judy's iPhone 4". The network connection was reset.
    Make sure your network settings are correct and your network connection is active, or try again later.
    I am trying to update the iPhone for my grandmother, Judy, as I am leaving for Paris on Wednesday night and we want to have Facetime installed on her iPhone before then, so we can stay in contact with each other. It is the simplest way for this to happen but the program simply will not allow me to update her iPhone.
    Is there any way to get past this error and update her iPhone? Any help will be greatly appreciated.

    Dear Jody..jone5
    Good for you that can't update your iphone because I did it and my iphone dosen't work for example I can't download any app like Wecaht or Twitter..
    Goodluck
    Atousa

  • I am unable to open raw files from my Canon T1i in Adobe Camera Raw of my version CS3 of Photoshop.  I have tried to update my ACR by downloading version 4.6 from the Adobe website but I am still unable to open raw files, just JPEG.  Is there a way to use

    I am unable to open raw files taken on my Canon Rebel T1i in my version of Photoshop CS3.  When I import raw files into Bridge they come up as patches with CR2 on them and when clicked on, a notice comes up stating that Photoshop does not recognize these files.  I tried to update my Adobe Camera Raw by downloading version 4.6 from the Adobe Website, but when I clicked on the plus-in, I got another message that Photoshop does not recognize this file.  I spoke with a representative from Canon who said that I could not update CS3 and that I should subscribe to the Cloud.  I would prefer to use my CS3, if possible.  Can anyone advise me what to do?

    The T1i was first supported by Camera Raw 5.4 which is only compatible with CS4 and later
    Camera Raw plug-in | Supported cameras
    Camera Raw-compatible Adobe applications
    Some options:
    Upgrade to CS6
    Join the Cloud
    Download the free Adobe DNG converter, convert all T1i Raw files to DNGs then edit the DNGs in CS3
    Camera raw, DNG | Adobe Photoshop CC

Maybe you are looking for