JTable Scrolling to a Specified Row Index

前端 未结 5 1848
梦如初夏
梦如初夏 2020-12-03 00:51

I have a JTable that is within a JScrollPane. Rows are added to the table at runtime based on events that happen in my application. I want to have the scoll pan

5条回答
  •  庸人自扰
    2020-12-03 01:03

    It's very easy, JTable has scrollRectToVisible method too. If you want, you can try something like this to make scrollpane go to to the bottom if a new record is added :

    jTable1.getSelectionModel().setSelectionInterval(i, i);
    jTable1.scrollRectToVisible(new Rectangle(jTable1.getCellRect(i, 0, true)));
    

    Where i is last added record.

提交回复
热议问题