Updating a JFrame's Background every second

Hello all,
What i want to achieve here is very simple, I have a class which extends JFrame. In my constructor, i create my GUI (background and buttons etc.), so here is my code :
//other imports goes here
public class TestBg extends JFrame implements ActionListener{
     //constructor
     public TestBg(){
          //.. other codes go in here
          //set the first background
          setContentPane(getImage());
          //create a timer which is invoked every second
          Timer timer = new Timer(1000,this);
          timer.start();
     //close constructor
     public void actionPerformed(ActionEvent e){
          //print a statement to see if method is invoked
          System.out.println("Method invoked");
          setContentPane(getImage());
}//close classlets say the method getImage() returns a JLabel, which set it to the JFrame's background.
The actionPerformed method is invoked every second, but the background isn't changing ( getImage() returns a different JLabel each time)
what extra code do i have to add ? thanks.
NOTE : I just discovered something, i think the JFrame needs to be repainted. Because whenever i resize the Frame, the background changes!, but i do not know how to 'referesh' the JFrame without resizing it.
Message was edited by:
TrAnScEnD3nT
Message was edited by:
TrAnScEnD3nT

That's because You add them to container that is an original content pane. Then when You call setContentPane this container is thrown away with all it's content and new "empty" container is put in that place.
I advise using a JPanel as a contentPane and don't change it on the run. Insted you can use the timer to repaint that panel with some image specified.

Similar Messages

  • Airplay stops when YouTube app is sent to background - every second video

    When I send a YouTube video to Apple tv and then switch to another app all is ok. However when I switch back to YouTube and start to Airplay another video and switch to another app again it stops Airplay streaming on Apple TV.
    I have to bring YouTube to front, click airplay icon, select Apple TV again and press play. Then I can switch to another app and Airplay continues. Then next video and Airplay stops again.
    So in simple words every second video plays ok and every second does not.
    Is it a bug or is it just me?
    I have iPhone 3GS.

    okay spoke a little too soon - deactivate is fired off on any
    time the app loses focus, not necessarily when it stops playing. Is
    there an event which signals right before the player is going to be
    paused? Thanks!

  • Updating JTable every second, want to ignore these events in my listener

    I have a JTable that I update every second using
    table.getModel().setValueAt(data, row, col);I'm also reacting to when the user clicks on a row in a the table, using a ListSelectionListener:
    public class MyTableListener implements ListSelectionListener {
              public void valueChanged(ListSelectionEvent e) {
                   if (e.getValueIsAdjusting()) return;
                   //do stuff
    }And of course I've done this:
    table.getSelectionModel.addListSelectionListener(new MyTableListener());Problem is, every time I update the table data it generates an event handled by valueChanged() above. I need to prevent this.
    Do I need a customized table model for this?
    Thanks!

    Found the problem: I forgot I was using JXTable, not JTable. Here's my example:
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.*;
    import org.jdesktop.swingx.*;
    public class Test {
         JXTable table = null;//change this to JTable to fix
         public class MyTableListener implements ListSelectionListener {
              public void valueChanged(ListSelectionEvent e) {
                   System.out.println("event="+e.toString());
         public Test()
              JFrame frame  = new JFrame();
              String columns[] = {"one", "two"};
              Object data[][] = {{0, 0}, {0, 0}, {0, 0}};
              table = new JXTable(data, columns);//change this to JTable to fix
              table.getSelectionModel().addListSelectionListener(new MyTableListener());
              frame.add(new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
                          BorderLayout.CENTER);
              startThread();
              frame.setVisible(true);
         public static void main (String args[]) {
              Test test = new Test();
         public void startThread()
              class RefreshThread extends Thread {
                   public void run() { try {
                             while(true) { SwingUtilities.invokeLater(new Runnable() {public void run() {
                                       updateTable();
                                  sleep(1*1000);
                        } catch (Exception e) {e.printStackTrace();}
              RefreshThread rt = new RefreshThread();
              rt.start();
         public void updateTable()
              TableModel model = table.getModel();
              try {
                   for(int row = 0; row < model.getRowCount(); row++)
                        model.setValueAt(System.currentTimeMillis(), row, 0);
                        model.setValueAt(System.currentTimeMillis(), row, 1);
              } catch (Exception e) {
                   e.printStackTrace();
    }When I change it to a JTable, valueChanged() is not called every time I programmatically update the table.
    If it's a JXTable, valueChanged() is called with every update. Annoying!
    To compile/run the JXTable version you'll need something like
    java -cp swingx-1.0.jar:. TestAs for the events themselves, I added print statements with e.toString() and the events are not distinguishable from user interaction. I wonder if this is a JXTable bug or feature.
    Thanks!

  • How to read two files (one is updating every second, the other is constant) simoltaneously

    Dear All,
    I will appreciate if somebody help me.
    I want to read two files, one is temperature wich is updating every second, and the other is hysteresis energy which has specific rows and is constant.
    I got a program in discussion forum which read a file as it is updating. I checked this program in my case and it works.
    Then I added reading hysteresis energy file to the existing file. But while i am running the program, the hysteresis energy file is read with all rows.
    But the aim is that everytime which temperature updates, I need to read just one row of the hysteresis energy file.
    so, in this way in every second i have a new temperature data and one row of the other file.
    I tried to used "for loop" inside the program, but it did not work, becuase reading temperature will be stopped untill for loop ends.
    I attached the program.
    Could somebody help me how to read just one row of hysteresis energy file everytime temperature updates?
    Solved!
    Go to Solution.
    Attachments:
    Readfiles.vi ‏23 KB

    I do not understand relationship between your two files.
    You have another VI or app that is writing data to both files and when new temperature data added you wish just to read the new data and then read one new line of the hysteresis file?????
    But is one is constant, why do you need to keep reading it?
    Anyway…
    The “Read From Spreadsheet File.vi” preformed an Open and a Close for each time it is called (if you will open the VI up and drill down and you will see). So that resets the file pointer back to the beginning and there for will read in the whole file from the first to the last each time if you do not set the start of read offset or number of rows.
    Now the Read from Binary File does not reset the file pointer and leaves the file pointer just past the last byte read so it will start with any new bytes automaicly only giving you the new data.
    I do not think you need to do the math with the Previous EOF=0 and the File size to get what I think you are trying to do.
    Plus use shift reg for the Data string instead of local var
    Set the mechinacl action of the stop botton to Latched
    So you do not need to init the two controls
    Also, I do not get the End of file encountered error (4) from the Read from Binary file if I attempt to read past. It just returns and empty string.
    Omar
    Attachments:
    Readfiles.vi ‏22 KB

  • IOS update image every second?

    Hello,
    I am very new to app development, so apologies for the simple questions.
    I have an image on a remote server of which updates every second, now I would like to put that image in a view in an app and have it effectively refresh every second.
    Currently its done using javascript and I just reference the image on the remote server with a time stamp on the end of the image like:
    image.jpg?Tue Jul 03 2012 10:57:08 GMT+0100 (GMT Daylight Time)
    Now I have this working with a local html file and a webview, I just wanted and think it should be possible using native iOS objects like the timer and image view.
    Just not sure how to achieve this.
    Any help is much appreciated.
    Thanks

    Any one?

  • Cursor only updates every second row

    Hello Helpful Peoples
    I have a table with a set of delivery dates, and am wanting to add a date on which a reminder flag should be raised by the system. The delivery dates are already populated and I'm wanting to add functionality where the end user can set how many days prior they are reminded.
    I've opened a cursor to retrieve all the current due dates from my source table. When I loop through this cursor and update the reminder date and reminder text, my code is only updating every second row.
    I can't work out why this code seems to skip a row every time it updates a record. Is anyone able to assist?
    declare
    v_date rep_delivery.reminderdate%type;
    v_rownum number;
    CURSOR reminder_cur
    IS
    SELECT DEL.DUEDATE
    FROM REP_DELIVERY DEL
    WHERE DEL.REP_ID = :P212_REP_ID:
    FOR UPDATE OF DEL.REMINDERDATE;
    begin
    FOR x IN reminder_cur LOOP
    FETCH reminder_cur INTO v_date;
    EXIT WHEN reminder_cur%NOTFOUND;
    v_date := v_date - to_number(:P212_REMDAYS);
    UPDATE REP_DELIVERY DEL2
    SET DEL2.REMINDERDATE = v_date
    WHERE CURRENT OF reminder_cur;
    UPDATE REP_DELIVERY DEL3
    SET DEL3.REMINDERTEXT = :P212_DESCRIPTION
    WHERE CURRENT OF reminder_cur;
    END LOOP;
    commit;
    end;

    Oolite,
    Use this code:
    DECLARE
       v_date   rep_delivery.reminderdate%TYPE;
       CURSOR reminder_cur
       IS
          SELECT        ROWID, duedate
                   FROM rep_delivery
                  WHERE rep_id = :p212_rep_id
          FOR UPDATE OF reminderdate;
    BEGIN
       FOR x IN reminder_cur
       LOOP
          v_date := x.duedate;
          v_date := v_date - TO_NUMBER (:p212_remdays);
          UPDATE rep_delivery del2
             SET del2.reminderdate = v_date,
                 del2.remindertext = :p212_description
           WHERE ROWID = x.ROWID;
       END LOOP;
       COMMIT;
    END;and it will work for you.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • When I plug in ipod, it connects/disconnects every second, forever..Win-7

    My ipod worked fine when I was running XP, but when I changed to Windows 7 (32bit), it started doing this thing where it would disconnect and connect every second, for as long as it's little heart desired.
    i tried:
    -letting it die
    -restarting it
    -all possible solutions provided by itunes help
    -putting it into disk mode
    -reformatting it (it worked on dad's comp: win xp)
    other facts:
    -it still charges
    -still plays music when not connected to computer

    Having the same problem with Vista Ultimate 64 bit. Started about a month ago. Gen 1 iPod video that I have updates and connects fine, just not my 4Gen Nano. Sent it in for repair, they sent me back a different one, having the same problem.

  • "Ghost" page numbers on every second page - how to remove?

    Hi,
    I'm setting a short book with Pages and after importing from Word, I'm seeing duplicate, partially hidden additional page numbers on every second page. I'd like to remove them entirely, keeping Pages' page numbering. Removing and inserting page numbers doesn't help and the second set of numbers can't be selected in any way (clicking, dragging don't work). One solution would be to re-import from word, deselecting page numbers beforehand, but I'd rather like avoid this step as I made many changes in Pages.
    Here's a screenshot showing the duplicate page numbers: http://dl.dropbox.com/u/3304376/pages_bug.png
    Does anybody have an idea how to remove them?

    Hello,
    Sometimes in the process of importing from Word, page numbers are improperly converted to Master Objects or Background Objects. Go to Format > Advanced > Make Master Objects Selectable. Then, with the cursor in the Margin of the document, press the Command Key (Cursor changes to an Arrow) and drag the cursor diagonally across the page number to select it. Then press the Delete key and the number should be gone. You need to check carefully to make sure that you have eliminated all the instances. There may be one per Section.
    Jerry

  • "Last devices used" menu every second over Ovi map...

    Hello all,
    I installed Ovi Maps on my phone, and have a huge problem with it: Every second the"Last devices used" pops up and goes away again.
    Since a few years I own (and use) a Nokia N95, and I just used 'Setup Nokia Maps Update 1.0.8.exe' to get Ovi maps on my phone. Apparently I had to use 'Nokia Software Updater' to make sure I got the latest version. Done that too.Next step is to use the Nokia Map Loader to get the maps on there. Done that too.
    Here is the version info of the installed map:
    I have Bluetooth enabled. Now, when I use the maps, every second the"Last devices used" pops up and goes away again. Mildly irritating would be a severe understatement here. Switching Bluetooth off and starting the map again gives the question "Bluetooth is currently switched off. Switch on?". Every second. It seems impossible to answer the popup-question or do something with the popup-menu.
    Is this a known prob by anyone, and can you please tell me a fix or workaround (preferably a fix of course)?
    Thank you,
    wlamee
    Solved!
    Go to Solution.

    And I got a nippy reply from the Benelux Nokia Care.
    The trick is I had to go to Tools -> Settings -> General -> Positioning -> Positioning Methods, and switch off 'Bluetooth GPS'. I think I always ahd this switched on and it never complained with the standard Nokia maps, but I'm not sure - I think I saw that menu only once, when I was palying with my GPS and the original maps.
    But hey, it's fixed. Cool!
    wlamee

  • Flex starting the video every second

    So I need some help, badly...
    I have a flex video player setup, and it's working great as
    long as I am pulling a video from the local drive like so:
    this.myVideoDisplay.source = "assets/media/testvidflash.flv";
    This plays great, works great, looks great... However if I
    change that single line of code to:
    this.myVideoDisplay.source =
    "rtmp://mydomain.com/media/video/public/testvidflash.flv";
    Then I get the video playing, but every second or so it
    starts another copy of the video in the background and I get this
    ever increasing echo.
    As best we can tell, the video file on the rtmp works fine in
    every other flash player we have tested, and I can create a new swf
    in CS3 and it works fine.
    Does anyone have any ideas?

    Mamata,
    thank you very much for your reply.
    What you say all make sence, and now I understand it better,
    I have a couple of more questions:
    1. When you say the network capability, you mean the viewer side or the server side?
    2. I read somwhere that the fms 3,5 has a feature of recognizing the users end speed and automatically adjusting the strem rate. So, it's eather I misunderstood the meaning of it, or this feature needs to be "switched on" somehow?
       Thank you

  • How can I stop (the annoying) McAffee Antivirus from downloading every time Adobe Flash needs to upate (which lately is every second day)

    How can I stop (the annoying) McAffee Antivirus from downloading every time Adobe Flash needs to upate (which lately is every second day)

    don't auto update.  manually update and untick mcaffee.

  • Outputting a data point every second

    I want to output a data point every second to an excel sheet. I got it so that it only outputs one accumlated data point. Each data point includes a timestamp, rate, and volume.
    Attached is my VI.
    Solved!
    Go to Solution.
    Attachments:
    PumpDriver Test 4.vi ‏82 KB

    Mike227 wrote:
    Hey Ravens,
    It never worked...the status isn't even updating which leads me to think that I am getting an error and not clearing it?
    If you post the code, we might be able to help you figure it out.  And errors happen for a reason.  Are you actually getting an error?  If so, what is the error?
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • ToolBoxTools.addEventListener only works every second time

    Hi!
    Our layouts pretty often click on the "page tool" by mistake and it happened a few times, that they changes the size of the page without even noticing. Because there is no way to remove the tool from the toolbar (I guess?), I wanted to write a script, that at least shows a message, that the page tool ("Seitenwerkzeug" in german) was selected. Unfortunately the event listener only works every second time:
    1. indesign starts > selection tool is active
    2. click on page tool > message appears > page tool is active
    3. click on "another tool1" > "another tool1" is active
    4. click on "another tool2" > "another tool1" is active
    5. click on page tool > nothing happens, the icon of the page tool is active, but the icon of the "another tool2" is still active, too, and "another tool2" is still activated
    6. click on "another tool3" > "another tool3" is active
    7. click on page tool > message appears > page tool is active
    8. ......
    Any idea why that is?
    My script:
    #targetengine myToolListener
    app.toolBoxTools.addEventListener ("afterAttributeChanged", changeToolAlert);
    function changeToolAlert() {
        if(app.toolBoxTools.currentToolName == "Seitenwerkzeug") {
            alert ("Message", "Title");
        exit(); //i tried with and without this!
    At the beginning I tried to use an confirm message instead of an alert, which had the same problem and I thought it might be because the changing doesn't work... but it seems I can't even work with the information without something "crashing" in the background?
    My previous confirm Function:
    function changeToolConfirm() {
        if(app.toolBoxTools.currentToolName == "Seitenwerkzeug") {
            var confirmDialog = confirm("Do you really want to activate the page tool?", true);
            if(!confirmDialog) {
                app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
    I really hope someone has an idea
    Best,
    Anke

    Hi Anke,
    The problem, I think, comes from the fact that the Page Tool selection event (which you listen to via afterAttributeChanged) needs some time to complete. Since the alert() or confirm() instruction gives the focus to a new modal window before the event life-cycle is finished, the GUI becomes instable, the PageTool icon state is not properly restored, and your event management goes wrong.
    A way to solve this might be to queue a temporary IdleEvent listener once the Page Tool selection event is caught. That is, we do not initiate any modal dialog as long as the GUI is refreshing.
    Something like this:
    //====================================================
    // PageToolDisclaimer.jsx
    //====================================================
    // Should be useable as a startup script, no #targetengine required
    // NB - MutationEvent is known to create a global 'evt' variable
    // so we don't seem to need a persistent session engine here :-)
    // That's why the active script File is used as the event handler
    (function(/*File*/EVENT_HANDLER, /*str*/TASK_NAME, /*uint*/TASK_TIME, /*str*/PAGE_TOOL_NAME)
        var t;
        // Installer
        if( !(t=app.toolBoxTools.eventListeners).length )
            t.add(MutationEvent.AFTER_ATTRIBUTE_CHANGED, EVENT_HANDLER);
            return;
        // IdleEvent handler (--> confirm)
        if( (t=app.idleTasks.itemByName(TASK_NAME)).isValid )
            t.eventListeners.everyItem().remove();
            t.remove();
            if( !confirm("***WARNING***\rDo you really want to activate the page tool?", true) )
                app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
            return;
        // PageTool event handler
        if( ('evt' in $.global) && 'currentToolName'==evt.attributeName && PAGE_TOOL_NAME==evt.attributeValue )
            evt.stopPropagation();
            app.idleTasks.add({name:TASK_NAME, sleep:TASK_TIME})
                  .addEventListener(IdleEvent.ON_IDLE, EVENT_HANDLER);
    })(app.activeScript, 'WaitPageTool', 400, app.translateKeyString('$ID/Page Tool'));
    Hope that helps.
    @+
    Marc

  • Page numbering every second page

    Hi guys,
    ok I have a 200 page booklet I'm doing, very simple - a notes page on the left hand side and then the contacts details on the right. But in the top right corner I need a page number that correlates with the contact. Problem is if I make page numbers it'll have them as 24, 26, 28 etc when that's not what I want.
    Is there a way to skip a page and just page number every second page?
    Thanks for any help,
    Dave

    It isn't entirely clear, but are we dealing with one person's contact info per page, or many? Sounds like 1.
    If it is, as I mentioned in your other thread, you could set this up as a Data Merge project. Create a two-page template spread, Add whatever you need for the notes page to the left page, and put all of your data fields on the right. You can include a number as one of the fields and palce it anywhere you want. This will only work with one record per page, though.
    If you'd rather number pages after the fact, it's probably scriptable to do something with starting a new section every second page and assign the numbers, or you could just add a master frame to the master page and place a number list, which is pretty simple.
    None of these techniques is truly automatic in the sense of updating if things are added or deleted, or if pages are rearranged. Any numbering outside the merge whould be done as the last step.

  • Why firefox freezes every second momentarily while loading webpages?

    Firefox freezes momentarily every second while loading pages and it is not smooth like other browsers out there..I'm facing this problem at home, office, etc with every stable/beta/developer versions!!! I've did all sort of troubleshooting procedures like reset, deinstall/reinstall, safe mode, etc. I'm facing this issue since the time i'm using this browser. Till now i'm with the hope that this issue will be cleared in the updated version!! But not!!
    To be brief, Firefox is not smooth like other browsers! Try to give me a solution to fix this issue! Else pls give me a statement that firefox is not capable of loading pages smoothly like chrome, opera, etc.. I'll happily uninstall this and use other browsers!!

    Hello,
    The Refresh feature (called "Reset" in older Firefox versions) can fix many issues by restoring Firefox to its factory default state while saving your bookmarks, history, passwords, cookies, and other essential information.
    '''''Note:''' When you use this feature, you will lose any extensions, toolbar customizations, and some preferences.'' See the [[Refresh Firefox - reset add-ons and settings]] article for more information.
    To Refresh Firefox:
    # Open the Troubleshooting Information page using one of these methods:
    #*Click the menu button [[Image:New Fx Menu]], click help [[Image:Help-29]] and select ''Troubleshooting Information''. A new tab containing your troubleshooting information should open.
    #*If you're unable to access the Help menu, type '''about:support''' in your address bar to bring up the Troubleshooting Information page.
    #At the top right corner of the page, you should see a button that says "Refresh Firefox" ("Reset Firefox" in older Firefox versions). Click on it.
    #Firefox will close. After the refresh process is completed, Firefox will show a window with the information that is imported.
    #Click Finish and Firefox will reopen.
    Did this fix the problem? Please report back to us!
    Thank you.

Maybe you are looking for

  • OAM 11g BP02 with Kerberos is not working on AIX

    Hi, We are trying to configure OAM 11g with Kerberos on AIX with no success.. Resource is protected according to OAM documentation guide but the oam logs shows the following: [2012-08-28T00:03:22.305-05:00] [oam_server1] [TRACE] [] [oracle.oam.engine

  • Build a sql query fro different table and insert into a table

    Hi I have a requirement , i have some table 1 table which holds rules which rules i have to apply on the sql query 2 table will hold table name and column name and transformation with these help of 2 tables i want to build a sql quey and the sql quer

  • Just tried to video chat and got only audio

    Hi! I am using iChat version 4.0.2 and was unable to video chat with my sister today. We could hear each other, but not see each other. On both ends, the only video we saw was from our own cameras. I tried changing the quicktime streaming to 1.5 and

  • I need to know the pricing for Team Ready for 10+ users.

    I need to know the pricing for Team Ready for 10+ users.

  • Help on DAO pattern

    Hello! I'm having a problem implementing the DAO pattern. Suppose that I have two database tables: emp(id, name, sex, deptid) dept(id, name) If I follow the DAO pattern, I use two DAO interfaces, one for each table, and "entity". EmployeeDAO, and Dep