Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2724
  • Last Modified:

Looping through and selecting rows in a Swing GUI JTable component

I want to loop through the rows of a JTable and select one or more of the rows based on a unique value (ID) for the row.  Also I would like to hide the ID column in the row of the JTable so that it is not displayed in the rows of the JTable.  How do I accomplish this?

Thank You,
Dave
0
gdkinney_2
Asked:
gdkinney_2
  • 2
  • 2
1 Solution
 
hoomanvCommented:
Use table.changeSelection(row, col, false, false) for each cell you want to be selected
0
 
zzynxSoftware engineerCommented:
int yourIDColumnIndex = 0; // I assume that your ID column is the first in the table
int theIDYouWantToSelect = 15; // Assume you want to select the rows with ID=15
int totalRows = theTable.getRowCount();
theTable.clearSelection();
for (int row=0; row < totalRows; row++) {
   Integer id = (Integer)theTable.getValueAt(row, yourIDColumnIndex);
   if (id.intValue() == theIDYouWantToSelect)
      theTable.addRowSelectionInterval(row, row);
}
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
 
gdkinney_2Author Commented:
zzynx no problem it's what I needed.

Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now