- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to deselect a range of rows from a table in Java?
Let’s say, we have selected a range of rows using addRowSelectionInterval() as shown in the demo screenshot −
Now, we will deselect the above shown selected rows using removeRowSelectionInterval(). The range is to be set here for interval i.e rows 3 to 6 (index 2 to 5) will get deselected −
table.removeRowSelectionInterval(2, 5);
The following is our example to deselect a range of rows −
Example
package my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws Exception { DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel); tableModel.addColumn("Language/ Technology"); tableModel.addColumn("Text Tutorial"); tableModel.addColumn("Video Tutorial"); tableModel.addColumn("Interview QA"); tableModel.addRow(new Object[] { "ASP.NET", "Yes", "Yes", "Yes"}); tableModel.addRow(new Object[] { "F#", "Yes", "No", "Yes"}); tableModel.addRow(new Object[] { "SharePoint", "Yes", "Yes", "Yes"}); tableModel.addRow(new Object[] { "AWS", "No", "No", "Yes"}); tableModel.addRow(new Object[] { "Blockchain", "Yes", "No", "Yes"}); tableModel.addRow(new Object[] { "C#", "Yes", "Yes", "Yes"}); tableModel.addRow(new Object[] { "Java", "Yes", "No", "Yes"}); tableModel.addRow(new Object[] { "NodeJS", "No", "Yes", "Yes"}); tableModel.addRow(new Object[] { "MVC", "Yes", "No", "Yes"}); // selected rows table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); table.addRowSelectionInterval(2, 5); // deselecting rows table.removeRowSelectionInterval(2,5); JFrame f = new JFrame(); f.setSize(600, 400); f.add(new JScrollPane(table)); f.setVisible(true); } }
Following is the output. Now you can see none of the row is selected −
- Related Articles
- Java Program to deselect a range of columns in a JTable
- Java Program to deselect all cells in a JTable
- How to add some rows to a table through DefaultTableModel in Java
- How to highlight multiple rows in a sequence in a table with Java Swing?
- How will you deselect an option from a static dropdown?
- Remove a range of elements from a LinkedList in Java
- How can we delete multiple rows from a MySQL table?
- How can we delete all rows from a MySQL table?
- How to select particular range of values in a MySQL table?
- How to count number of rows in a table with jQuery?
- How to select all rows from a table except the last one in MySQL?
- How to sort rows in a table using JavaScript?
- Copy all rows of a table to another table in MySQL?
- Fetch random rows from a table with MySQL
- Create a MySQL table from already created table selecting specific rows?

Advertisements