• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable scrolling

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a little problem, and I'm not sure if it is a scrolling issue, or a JTable issue, but I'll explain what I'm trying to do, and hopefully somebody will understand.
I have a JTable with nothing in it(will call this JTable1). The user selects a row from a different table(JTable2) and clicks the "Add" button. This grows my JTable1 by one row. After I do several adds, my JTable1 gets a scrollbar associated with it. The current behavior is that once I have this scrollbar and I add another row, my view never changes from the first few rows(the ones visible prior to my scrollbar popping up). I don't see the last row added unless I manually go over and scroll down.
What I want to happen is that once the table is large enough for the scrollbar, I want to set the current visible row to be the last one that I added. Basically I want the table to automatically scroll to the last row added.
Any assistance is greatly appreciated!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After you add the row, you need to tell the JTable to scroll... use the scrollRectToVisible(Rectangle) method to do this. The rectangle doesn't have to enclose the entire row width (unless your rows are wider than the scrollpane and you want to scroll to the first column or something), so you can use getRowCount() and getRowHeight() (or getRowHeight( int row ) if your rows are different sizes) to calulate the location you want to scroll to be visible.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic