Views using the same offscreen buffer, interfering with each other

Hi all,
I am creating an application where I display simulations. In order to keep the view of the simulation ticking along nicely, I paint the view to an offscreen buffer, and then paint the offscreen buffer to the screen.
This has worked fine for me, so long as I was only viewing one single simulation on the screen at a time. I have now started displaying multiple simulations, and the views have started to interact with eachother -- one will paint over the other, particularly when I click or drag the simulation.
I'm not using any static variables, so my guess is that the fault is the offscreen buffer that I'm using. I think my various views are using the same buffer. Is it possible that this is the problem?
Here's how I paint my view:
private BufferedImage offImg;
private Graphics2D offG;
public Graphics2D createGraphics2D(){
          if (offImg != null) {
               offImg.flush();
               offImg = null;
          RepaintManager repaintManager = RepaintManager.currentManager(this);
          try {
          offImg = (BufferedImage) repaintManager.getOffscreenBuffer(
                    this, this.getWidth(), this.getHeight());
          } catch (java.lang.NullPointerException e){
               return null;
          offG = offImg.createGraphics();
          // .. clear canvas ..
          offG.clearRect(0, 0, getSize().width, getSize().height);
          return offG;
private void draw() {
      if (offG == null)
               createGraphics2D();
     offG.drawImage(...) //etc
public void paintComponent(Graphics g){
           g.drawImage(offImg, 0, 0, this);
      }My first thought was to create a list of all the offImg's created and compare them. The different views are indeed getting the same image from repaintManager.getOffscreenBuffer, even though the component passed in as 'this' is different. The offG's created by each view are different, but since they belong to the same image, I assume it's the image that's important.
Is this likely to be the source of my woes, and, assuming that I want to keep using the offscreen buffer (I do) is there a way around this problem?
Thanks so much for any advice.

Hello,
I am creating an application where I display simulations. In order to keep the view of the simulation ticking along nicely, I paint the view to an offscreen buffer, and then paint the offscreen buffer to the screen.You may know that Swing uses double-buffering by default. So you usually don't really need to tweak Swing's own offscreen buffers.
Painting conservatively on an applicative offscreen buffer is sounds (if painting is slow), but then your application has to create a dedicated offscreen buffer, not use Swing's ones.
This has worked fine for me, so long as I was only viewing one single simulation on the screen at a time. I have now started displaying multiple simulations, and the views have started to interact with eachother -- one will paint over the other, particularly when I click or drag the simulation.
I'm not using any static variables, so my guess is that the fault is the offscreen buffer that I'm using. I think my various views are using the same buffer. Is it possible that this is the problem?I can't tell for sure, but I'm not surprised if that's the case: all Swing ("lightweight") widgets within a same JFrame (or any other "heavyweight" top-level container) share the same native graphical resources, so presumably share the same offscreen buffer. It is Swing's machinery that arranges so that each widget paints onto a part of this buffer that corresponds to the widget's bounds.
          offImg = (BufferedImage) repaintManager.getOffscreenBuffer(
                    this, this.getWidth(), this.getHeight());You don't have to, and probably should not, ask Swing's RepaintManager for a buffer. You vould create a BufferedImage yourself, then draw onto it.
offImg = new BufferedImage(...);Then your paintComponent method itself is fine:
public void paintComponent(Graphics g){
           g.drawImage(offImg, 0, 0, this);
Is this likely to be the source of my woes, and, assuming that I want to keep using the offscreen buffer (I do) is there a way around this problem?See above. And look for "offscreen graphics" on this forums, you'll probably find a lot of examples that do this way (and give example code, my sample above is sketchy and untested).
Regards,
J.
Edited by: jduprez on Jun 2, 2011 12:10 AM
Read this article if you need to kick the best out of your fast painting code (in particular, it mentions more informed ways than mine to create Image instances suitable for offscreen drawing):
http://java.sun.com/products/java-media/2D/perf_graphics.html

Similar Messages

  • Can two players use the same game app without erasing each other's scores?

    Can two players use the same game app on the same device without erasing each other's scores?  My two sons build up their characters and progress in their games, then the other one wants to play, erasing the first son's progress.
    Is it possible to create two player identities in the Game Center? 
    Is it possible to have two different Apple User ID accounts on the same device?  Is that even desirable?
    Many thanks!
    MCPROBW

    You can create as many individual user accounts on a Mac as you like. Then, any one or more of those users can remotely log in from another Mac and use that Mac as their own, simultaneously. Each account will remain separate from all others.
    However, since each user needs to have a Mac to do that, I'm not sure how you could effectively double the number of users as you describe.

  • Can 2 different iphones be registered to the same pc without interfereing with each others apple accounts?

    can 2 iphones be used on the same pc

    IMO, if the two phones are used in the same family, I would use 1 iTunes account for both iPhones.  You can select which stuff you want to sync to which phone and iTunes will keep track of it.  I do this with a 4S, 3G, iPad2 and Touch, all with the same iTunes account.

  • Home sharing suddenly stopped working. All devices have home sharing enabled, all devices are using the same network but cant see each other

    I've gone through all the Googling and support forums I can handle.. They all tell me to the same things. I have done everything required and quite honestly Home Sharing was working for quite some time. So I don't think I changed anything.
    The only culprit I can think of is the wireless network. We had to call Comcast and reset our service, and they gave us a new modem. Our router is also new.
    Is there a setting in a router that lets multiple devices connect but blocks each of them to each other? That seems to be what's happening.
    Apple TV2 can see our connection no problem and can download trailers (downloading movies never works though!!!), we have two Macs and two iPhones and all are on our wireless and none can connect to one another using Home Sharing.
    Please help!! This is an odd one!!

    I believe this is true. Alas, I wrote this a while ago and the link is dead. I can't totally remember what the issue was.
    But, looking through the PDF for the Linksys e2000, searching for 'filter multicast' I see this:
    Filter Multicast The multicasting feature allows for multiple transmissions to specific recipients at the same time . If multicasting is permitted, then the Router will allow IP multicast packets to be forwarded to the appropriate computers . Select this option to enable the filter . This option is disabled by default.
    And in my settings it's been enabled. So maybe try that.
    Filter multicast is under Securtiy>Firewall after you log in as admin.
    Why it's disabled by default I do not know.
    Good luck! Hope this is the solution!! Apple should warn people of this feature conflict to Apple TV buyers.

  • How to sync 2 different Mac users using the same Apple ID and with out mixing each other info?

    How to sync 2 different Mac users using the same Apple ID and with out mixing each other info?
    We are two people using three difrent Macs, 1 Iphone and 1 Ipad with separate USERS  on each Mac but sharing the same Apple ID: xxxxxx
    I set up the first user to iCloud and it was OK but when I set up the second user to use iCoud the first users's info gets mixed with the second user's info?
    Do we have to set up a diffrent Apple ID for each other?
    Sometime ago I added my friends E mail (yyyyy) to the main Apple ID (xxxx) as for using his E mail account (to separate our e mail accounts, and it's working ok) but now when I try to create a new apple ID whith the same friend's e mail (yyyyyy)  it says that his mail (yyyyy) is already an apple ID when the Apple ID is really my E mail (xxxxx)... any clue?
    Thanks

    I believe because you migrated from a Nokia to an iPhone you need to register the Bn phone number with your Apple ID so it can be used for iMessage. The Pn number seems to be the only one registered
    Go here > https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/
    Manage your Apple ID and see if that does the trick
    Hope that helps

  • I have purchased apple phone 4s for india (non-carrier). Can i use the same phone in USA with usa based sim

    I have purchased iphone 4s for India from India. Can I use the same phone in usa with usa based sim

    An unlocked phone is an unlocked phone, which is the same for the iPhone.

  • HT5824 Can use you use the same icloud & itunes account with 2 different cell phone numbers?

    Can I use the same icloud & itunes account with 2 different cell phones that have 2 different numbers?

    Yes. Two iDevices can share the same iTunes Library as long as both are configured to use the same Apple ID.

  • We use Thunderbird all the time and love it, but for about a week it constantly goes into not responding mode. My boss uses the same service at home with no pr

    Thunderbird is a great asset to my boss and I. We use Thunderbird all the time and love it, but for about a week it constantly goes into "not responding mode". My boss uses the same service at home with no problem at all.
    I did an "safe mode" and restart and for a few minutes I thought it was "healed". However, I did a search and the same thing started happening again. The little blue ring starts spinning and "not responding" pops up above the toolbar. Sometime the screen fades to a sort of greyish and no mouse click are responded to, even to close Thunderbird.
    Please help however you can. Our office number is 512.246.3995.
    Thank you,
    Mary

    We wonder if it is a firewall problem that developed here at the office. My boss uses her account at home and all is well, but here, experiences the same issues I described

  • My sister and I each have an ipod touch. We use the same computer and itunes but each have our own apple id. Everytime I want to update an app on my ipod it asks for my sisters apple id login!? help!

    My sister and I each have an ipod touch. We use the same computer and itunes but each have our own apple id. Everytime I want to update an app on my ipod it asks for my sisters apple id login!? help!

    When it asks for another ID on an App Update, it means that the application was purchased under your sister's ID but downloaded to your device from the iTunes library that you share. Even though you both have your own Apple IDs, since you are syncing on the same computer, you are using the same iTunes library.
    Whoever purchased the app is forever tied to it, and you can only have one version of a particular app in a single library....
    Does that make sense?
    Cheers,
    GB

  • When World it be able to log on to The same pages document and see each other corrections When you write/type Them.

    When will it be able to log on to The same pages document and see each other corrections as soon you write/type Them?

    Then use Google Docs if it does what you want.
    MsOffice and LibreOffice are also coming to the iPad, we shall see what they have to offer.
    With luck neither will use iCloud. Apple has yet to get anything right in networking.
    Peter

  • I've had my iphone 5s since march 2014  and I've been using the same charger it came with. for the last two weeks ive been getting a message saying the accessory may not support the device. how is that possible?

    How come I keep getting a message saying that the accessory may not support the device?  I've been using the same charger that came in the box with the phone. Now it doesn't charge at all.

    Then take the cable, the plug and your iPhone to an Apple Store genius bar it is still  under the 12 month warranty

  • Can I use the same apple I.D. with two iPods?

    I have a 4th gen iPod, but I'm interested in purchasing a 5th gen. However, I'd like to use
    my same apple i.d. instead of creating a new one and losing all my game and music data.
    Is it possible to use my old one?

    Of course. You should use the same AppleID on all your devices. Why would you create a new one?
    Matt

  • Wireless keyboard & wireless mouse interfering with each other

    Hello,
    Since I've had the mac, my wireless mouse and keyboard interfere with each other.
    The mouse tracks very slowly, and I have to keep waking the keyboard.
    This seems to happen when I'm using Safari and the airport.
    I have new batteries.
    Any ideas please.
    Thanks for help over this very frustrating problem.
    Trump Marker.

    I am having the same problem. Now, my wireless mouse sometimes works, mostly doesn't, and often sends the text into spasms (suddenly shifting to the right, or wildly highlighting passages) that require quitting Safari or Word. A few times I haven't even been able to force quit. And one time my computer started making a godawful noise, like it was wailing, until I had to shut down with the power button. I'm sooo sorry I downloaded this update and would like to hear from an Apple representative!

  • (Possible solution found) Can my wife and I use the same Lion DL even with two separate Apple IDs?

    EDIT: Sorry; original search terms didn't give me my answer. I think I found a solution though. Will update whether it works out.
    My wife and I each have our own MBPs, and we each have our own Apple IDs that pre-existed our marriage. Apple doesn't make it easy to have one family account with subaccounts managed underneath this, and we don't want each others iTunes purchases populating our libraries.
    Is it possible for me to DL and install Lion with my Apple ID, copy it to hers, and install it there with my same info yet still allow her to use her own ID for other things? Or will we need separate IDs for each download?
    Message was edited by: super reubs

    iTunes: How to share music between different accounts on a single computer - http://support.apple.com/kb/HT1203 - relocating iTunes' media folder to a shared area but leaving separate library files - extra tip at https://discussions.apple.com/message/17331189
    Chris CA's instructions on sharing one iTunes music library between multiple user accounts - https://discussions.apple.com/message/8974074 - Multiple users using a single library file - similar post at: https://discussions.apple.com/thread/3753008
    Suggestion by Turingtest for multiple users and one library - http://discussions.apple.com/message/9117622 - use smart playlists and tags to isolate groupings.
    Discussions on using purchases from multiple AppleIDs in one iTunes library - https://discussions.apple.com/message/19543804

  • Can I use the same drive to backup with Time Machine and Windows Backup?

    I've got a 1TB external hard drive that I'm currently using for Time Machine backups and also it stores about 300GBs of music. Can I partition the drive to add an NTFS formatted partition and use that partition with Vista's Backup/Restore feature? If so, how do I partition the drive? Forgive me, I'm a neophyte when it comes to Windows. Also, I don't want to lose the music files already saved on the Time Machine partition.

    While you can add HFS+ volumes to an existing drive, adding NTFS requires taking chances: change to FAT and then convert to NTFS.
    I'd invest in another backup. I don't even rely 100% on any one backup method; drive; let alone TimeMachine. A bootable backup should also be part of your strategy for OS X. So I would create a smallish 40GB emergency boot volume - for OS X use only.
    For Vista, I use the built-in features of Ultimate/Business AND Prosoft Engineering DataBackup PC. Norton Ghost started out okay but gradually deteriorated, though their 2009 360 2.0 or something....
    I would not want to use WinClone except as one-time 'snap shot' or emergency; useful when moving to a new larger hard drive, and if your Vista partition is small and not 100GB of files.
    I'd look at 500GB+ drive to use solely for Vista backup and media files.
    MacSales has $79-89 FW800/400 case for SATA drives, and just throw a good 640GB WD Caviar in for $78 and good to go.
    http://eshop.macsales.com/item/Other%20World%20Computing/MEFW934AL1KS/
    http://eshop.macsales.com/item/Other%20World%20Computing/MEFW934FWU2K/
    http://eshop.macsales.com/item/Western%20Digital/WD6400AAKS/

Maybe you are looking for

  • Windows 2008 Server Std on T500

    Hi. Is there anyway to install Windows 2008 Server Std. on a T500 with Windows 7 installed? We've tried to install it and the drivers are all screwed up -- the network, video, and other "base" drivers are all missing. We tried using the Vista and XP

  • I have a Pixma Pro 100. Does anyone know what printer setting I would use to print on 11 x 14 paper?

    I'm trying to make 11 x 14 prints but I'm unsure what what size to set it as in Photoshop. I'm using Epson paper which works fine with the printer I just don't know what settings to use. Thanks.

  • System status for Internal order

    Dear SAP gurus, I want to automate the system status for Internal order that at the time of Final billing of invoice , the Internal order should be closed automatically. Is there any setting to do this. Thanks,

  • Speakerphone bug identified in 1.1.2

    While on a call using speakerphone, adjust volume while you talk. Your voice will completely drop out to the listener on the other end. Drop outs seem to last about 3-4 seconds, enough to drop 4-5 words or so each time you press the volume (in either

  • My internal drive is filling up by itself. cannot find any huge files.

    my internal drive is filling up by itself. cannot find any huge files. backing up onto external drive which has room. OSX 10.6. created an external library for aperture to make space. created 32 gigs on my internal disc, down to 8oo megs overnight. w