Solved

Looping through and selecting rows in a Swing GUI JTable component

Posted on 2006-11-02
5
1,986 Views
Last Modified: 2008-03-03
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
Comment
Question by:gdkinney_2
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 17864513
Use table.changeSelection(row, col, false, false) for each cell you want to be selected
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17864519
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 17865362
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
 
LVL 37

Expert Comment

by:zzynx
ID: 17912411
Thanx 4 axxepting
0
 

Author Comment

by:gdkinney_2
ID: 17926178
zzynx no problem it's what I needed.

Thanks!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now