Solved

Looping through and selecting rows in a Swing GUI JTable component

Posted on 2006-11-02
5
2,088 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 86
Cipher Configuration on Apache HTTPD 4 64
HTTPSessionBindingListernter not configured in deployment descriptor 2 55
ForLoop Example 3 49
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

825 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