In this example I’m going to discuss about how to select one whole row or a column when a cell in a JTable is clicked. It’s not something hard, since it just requires 3 lines of code to be included. Follow the steps below to make it happen.
Steps:
Steps:
- Since we are just going to select one particular row or column in a JTable, the selection mode has to be set as Single selection using the constants in ListSelection Model Interface. E.g: jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- If row selection is to be enabled, set the row selection method as “true” and column selection method as “false”. Code snippet and output are as below.
- If column selection is to be enabled, set the row selection method as “false” and column selection method as “true”. Code snippet and output are as below.
Author: Thiagu
No comments:
Post a Comment