Programmatically select a row in JTable

后端 未结 3 1012
予麋鹿
予麋鹿 2020-12-24 10:37

When the application is started, none of the rows is selected. But I would like to show that the first row is already selected.

How to do this? Do I need to set the

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 11:21

    It is an old post, but I came across this recently

    Selecting a specific interval

    As @aleroot already mentioned, by using

    table.setRowSelectionInterval(index0, index1);
    

    You can specify an interval, which should be selected.

    Adding an interval to the existing selection

    You can also keep the current selection, and simply add additional rows by using this here

    table.getSelectionModel().addSelectionInterval(index0, index1);
    

    This line of code additionally selects the specified interval. It doesn't matter if that interval already is selected, of parts of it are selected.

提交回复
热议问题