Keeping Viewport position when rows above viewport are deleted from JTable?

I have a JTable backed by a vector. I have, say, 30 rows and my Viewport is showing the ten rows from row 11 to 20. I want to be able to delete one of the first 10 rows without having my viewport slide so that it displays what were formerly rows 12-21. Essentially, I want the position of the viewport anchored to the rows shown in the viewport, not anchored to the row numbers position in the table. I have been able to do this by moving the viewport Rectangle by getRowHeight with each delete but that makes my table flicker when rows are deleted and is generally an ugly solution. The table is sorted so that the rows are not necessarily displayed in the order in which they reside in the vector.
Here is the ugly way to accomplish what I'm talking about:
JViewport viewport = null;
java.awt.Point p = null;
// if the order is being removed from above the current viewport
// scroll down one row so the viewport remains stationary during deletes.
if (table != null && (table.getParent() instanceof JViewport)) {
     viewport = (JViewport) table.getParent();
     int h = table.getRowHeight();
     Rectangle rect = table.getCellRect(row, 0, true);
     p = viewport.getViewPosition();
     //if the row being deleted is above the viewport
     if (rect.getY() + h < p.getY()) {
          // The location of the view relative to the table
          // Scroll the area into view.
          h = h * -1;
          p.translate(0, h);
          viewport.setViewPosition(p);
displayedVector.remove(row);
fireTableRowsDeleted(row, row);
Thanks!
Andrew Munn
[email protected]

What am I doing wrong?Nothing.
The DataModel stores data. The ColumnModel is used by the table to display the data from the DataModel in a certain order. If you don't want to display a column that fine, but there is no need to delete the data.
If you want to delete data from the DataModel the look at the DefaultTableModel API setColumnCount(int) method.

Similar Messages

  • HT201317 The pictures in my photostream folder on my computer are being deleted when the pictures are deleted from photostream on individual devices.  The photos on the computer were supposed to be permanent.  Can I stop photostream from deleting from my

    The original photstream instructions, and the current photostream information page on the apple website, say that photos on your pc or mac computer that have been synced by photostream are permanent but the latest updatge seems to have changed that so when items are deleted from any device they are deleted from all devices, including images that have gotten older and have rolled out of photostream on my iphone.  I trusted photostream to save these images on my computer and now they appear to be gone.  Can I turn off the option of deleting photostream images from my computer or do I need to copy these images to another folder to save them from being deleted when they are deleted from the device.

    MikeMurdock wrote:
    ok so i can't figure this out because i keep being told different things by everybody.
    so say I take a picture with my phone. that picture is now located in my camera roll and uploads to my iclouds photostream, which I can then view on my computer. now my question is this: is the photos in my stream, on my comp permanent, allowing me to then delete them from my phones camera roll?
    No
    Photostream keeps them for 30 days.

  • Error message (-51) keeps coming up when I try to send music from iTunes to my iPhone and then the music won't come over.  How can I fix this message?

    Error message (-51) keeps coming up when I try to send music from iTunes to my iPhone and then the music won't come over.  How can I fix this message?

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2

  • I am unable to see any POP3 or IMAP tab when I set up an account in my iphone 4S. Hence by default all my email accounts become IMAP and the messages are deleted from the server when I delete them from the iphone.

    I am unable to see any POP3 or IMAP tab when I set up an account in my iphone 4S. Hence by default all my email accounts become IMAP and the messages are deleted from the server when I delete them from the iphone.

    ok sorry everyone but i solved it myself but the solution is so nuts i've posted it here to help others who have the same problem.
    to setup a comcast imap account on your iphone:
    go to mail, contacts, etc in settings
    under accts, select add account
    select "other"
    new screen, choose "add mail account"
    now on the new acct screen you must enter your name, email address and password for your GMAIL acct ! (yes i said your gmail acct !, or some other acct with a NON comcast address).
    hit next
    then the acct verifies
    when verified a screen will open with all the acct settings for this acct AND @ the top of the screen are the 2 buttons > imap or POP
    select imap and THEN CHANGE ALL THE ACCOUNT information to the comcast account !
    then hit next and the account will take a couple minutes to verify but it will verify and now you have a comcast imap acct set up on your iphone.  The problem must be that when the iphone sends the initial verify acct info to comcast (if you enter that information first) the comcast server is simply not setup yet to signal the iphone that there is an imap option.

  • Does iPhoto not have safeguards against accidentally deleting an entire photo book, which is very easily done (when you think you are deleting just a photo)? No "are you sure you want to delete?". No way of copying your book before, or restoring it after?

    Does iPhoto not have safeguards against accidentally deleting an entire photo book, which is very easily done with a single press of delete (and which can be done when you think you are deleting just a photo)? No "are you sure you want to delete?" before it happens? No way of copying your book while you are working on it (to make multiple versions of it, or just to have a safeguard copy), and no real way of restoring it after (since, remarkably, the photo books don't appear as items - items which could very easily be recovered otherwise)?

    I get a dialog box when I try to delete a book.
    And if you right click on the book in the left column you can duplicate it so you can have multiple versions.

  • Why is it on the photo app is that when you add your photos to new albums and when you are deleting from camera roll it will delete photos from everywhere so therefore once your photos are in the albums you have chosen you cannot delete f

    Why is it on the photo app is that when you add your photos to new albums and when you are deleting from camera roll it will delete photos from everywhere so therefore once your photos are in the albums you have chosen you cannot delete from camera roll

    Your photos are actually all in the Camera Roll.  The album you create only contain pointers to these pictures.  Albums are like music playlists; when you delete a song from the playlist it doesn't delete the song from your music library.  But when you delete a song from your music library it will also be deleted from any playlists that it may have been in as well.

  • Yahoo/att email from my ipad2 are deleted from the server view.

    When reading my yahoo/att email from my ipad2 they are deleted from the server view. Is there any way to keep this from occuring? I have my home pc set to not delete upon reading to allow manual retention as needed.

    If you recently added back your email account it was most likely set up as an IMAP account - renowned for the seamless sync across your device - yes I am being a little sarcastic there - at the technology not at you
    The oft recommended way to "force" the email to be POP is to add your email address in there incorrectly - misspelling works fine - and then it asks whether you want a POP or IMAP account
    Try that - delete the account - you will not lose your emails in there
    Then re add and follow the steps I recommended and see if that solves your issue

  • My emails are deleted from the server daily. I checked leave emails on server? This is a new problem, My emails would always be on the server until I deleted

    On a daily basis my emails are deleted from the server, even if I still have them on my computer.

    Actually, it had to do with Comcast, not the iPad. The default for Comcast is IMAP, and that is based on the information they have available when the account goes into verification. It verifies an IMAP account, and since you have not migrated to the IMAP account, you were having problems. It isn't something anyone can fix, except you. It would not ask you at the beginning if you wanted IMAP or POP, it has to do with the mail provider's verification settings, which is a Comcast issue, but because they are providing IMAP now, it defaults to that. If you are still using POP, you have to force the mail app to get there, which is what I provided you the instructions for. Apple is not going to fix anything, because there is nothing for them to fix.
    Either way, you got it fixed and that is all it takes. As a Comcast customer, I was aware of this, since I had migrated to IMAP already.

  • Hello, All my sonds are deleted from my laptop and from Itunes. If i synch my iphone to my itunes all my music will go. How do i prevent losing all my music?

    Hello, All my sonds are deleted from my laptop and from Itunes. If i synch my iphone to my itunes all my music will go. How do i prevent losing all my music?

    There's some third party applications available for recovering content off an iPod, iPhone or iPad. The following article is pretty old (2008) so it would be best to reality-check the capabilities and availability of the various listed items prior to opting for a particular product:
    http://www.ilounge.com/index.php/articles/comments/copying-music-from-ipod-to-co mputer/P2

  • Any ideas why I have emails received on iphone but are deleted from p.c ?.

    Does anyone have any ideas as to why I receive Emails on my Iphone, but they are deleted from my p.c.?

    You're using a POP account instead of IMAP. That's how it works.

  • HT4946 by mistake my contacts are deleted from iphone and the pc which itunes installed is corrupted, i have the itunes backup folder,is this possible to restore the contacts from my old itunes backup folder to iphone!?

    by mistake my contacts are deleted from iphone and the pc which itunes installed is corrupted, i have the itunes backup folder,is this possible to restore the contacts from my old itunes backup folder to iphone!?

    unless you had them synced with icloud or some other email account, very unlikely

  • Hi, messages still appear in iPhone search even after they are deleted from iPhone.

    Hi, messages still appear in iPhone search even after they are deleted from iPhone.

    Yes and as long as you are signed into iCloud - you can even use that phone to iMessage
    The messages stay on there until you wipe / erase / restore your old phone

  • Can I get my contacts back if they are deleted from ICloud?

    Can I get my contacts back if they are deleted from ICloud?

    If your contacts is gone from iCloud.com there is only a few ways to possibly recover it.
    The first things I would check is a iCloud Backup, a iTunes Backup, or a 3rd party email that may have contained the contacts. To restore from a iCloud or iTunes backup follow this link. This article explains how to restore a device from either back up.
    Note if you have backed up since the contacts went missing, you will not have the contacts on the backup. Make sure you do not back up if trying to restore from a back up as this will back up the content without the contacts.
    To get to the "Set up assistant" on an iOS device, you must go to Settings>General>Reset>Erase All Content and Settings. Once the phone restarts, you will be at the "Set up Assistant"
    Gmail emails are very commmon sources for contacts and you may have been adding them to the gmail contacts without even knowing it.

  • Keep layout position when using Find/Change?

    When using Find/Change in InDesign CS4, each occurrence of the "Found" material is centered in the window, so the page moves around with each find. Is there a way to keep the page in a fixed position when searching through a document?

    Actually, I can think of a shortcut for the hard part: The user uses the
    regular find/change UI to make all their settings. Then, they run the
    script, which will simply use the settings in the UI. Nice, huh! So you
    could get a listBox of all the finds -- select the entry and you get
    taken to the desired location. Click the "change" button and the change
    is made. Here's a proof of concept:
    #targetengine engine20
    var myFinds = app.findText();
    var w = new Window("palette");
    var myList = w.add("listbox", undefined, myFinds);
    var changeButton = w.add("button", undefined, "Change");
    myList.onChange = gotoFound;
    changeButton.onClick = makeTheChange;
    w.show();
    function gotoFound(){
    app.select(myFinds[myList.selection.index].parentTextFrames[0].parent.parent);
         app.select(myFinds[myList.selection.index]);
    function makeTheChange(){
         myFinds[myList.selection.index].changeText();
    Obviously very rudimentary: but this does work in CS4. If the list is
    too long, though, the change button will disappear off the bottom of the
    screen. Also, really once the change is made, the item should be removed
    from the list, but there's a bug in CS4 that makes it impossible to do
    that simply, if I recall correctly (or was that only a tree list?)
    Also, I have found that the only sure way of getting the entire spread
    to show is as I've done it above (and it would need much more error
    checking than this -- for instance, overset text).
    Ariel

  • Lightroom 3.3 having problems keeping pan position when printing

    Has anyone else run into the problem when printing from LR 3.3 that was fixed in LR 3.2. - namely
    Print: Image loses “pan” position when placed in cells that are not big enough
    When LR 3.0 was out they released 3.2 and fixed the above problem.  Recently when printing from 3.3 I noticed that it could not retain any image pan whilst in cells on the sheet that are not big enough. It does not matter whether or not there is one image of multiple, it seems to suffer from the same problems, with all images defaulting to the right hand margins.
    I can confirm that 3.2 did indeed fix the issue, but it seems to be back in 3.3
    Can anyone else confirm this issue?
    MacBook - 4GB Ram - 100Gb free space - OS X 10.6.5
    Epson R2400 printer + Latest Epson Print Drivers
    Canon CR2 images from 1Ds3

    HI Jim...sorry about the delay in replying, have been away....what you suggested didn't work i'm afraid, but thanks for trying...earthpilgrim

Maybe you are looking for

  • New Dial plan & Voice policies not taking effect with Polycom CX 600 Desktop Phone in production deployment, Worked fine in Testing

    Hi, We are in the process of Migrating Cisco CUCM & Voice Gateway (From another vendor to Cisco). The requirement is all internal calls between Cisco IP Phones & Lync to be flown through CUCM. Means internal extension to extension. Remaining all call

  • Is Quick Time player the same as QT Movie?

    I am trying to convert an MP3 audio file to AIFF. I'm used to using QT but now, I can't seem to get the conversion to happen. Is it because I am using QT P;ayer instead of Movie, and if so, how do I fix this? Thanks in advance... PowerMac G-4   Mac O

  • VBFA field

    Hi, I am having a hard time to identify, how the field stufe in vbfa is used. In the table description is says (Level of the document flow record) but i don't know how it can be used in a "where" condition on the "Select" on the table. Thanks.

  • ThinkVanta​ge System Update

    On my laptop I uploaded Windows7_SP1 T500. After installing SP1, which ran OK, I've noticed that does not work ThinkVantage System Update. 9% below the notice himself. http://www.shrani.si/f/1Y/TL/4lmzdQGi/update.jpg Solved! Go to Solution.

  • Problems viewing youtube "upgrade flash player "message

    I'm having trouble viewing youtube I keep getting a warning to up grade my flash player and i do ,but to no avail . I'm stuck in a loop and can't view many videos ...Its all so frustrating Please Help