- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Java Program to deselect all cells in a JTable
At first, let’s say, we have selected a row using addRowSelectionInterval() as shown in the demo screenshot −
Now, we will deselect all these cells using clearSelection() as shown in the following example. This method clears the selected cells from the table −
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 a row table.addRowSelectionInterval(2, 2); // deselecting table.clearSelection(); 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 cell is selected −
Output
- Related Articles
- Java Program to deselect a range of columns in a JTable
- Java Program to select all cells in a table
- How to set magins between cells of a JTable in Java?
- How to select different cells of a JTable programmatically in Java?
- Java Program to select a column in JTable?
- Java Program to append a row to a JTable in Java Swing
- Java Program to enable cell selection in a JTable
- Java Program to enable column selection in a JTable
- Java Program to increase the row height in a JTable
- Java Program to add Combo Box to JTable
- Java Program to display only vertical grid lines in a JTable
- Java Program to display only horizontal grid lines in a JTable
- Java Program to retrieve the value from a cell in a JTable
- How to deselect a range of rows from a table in Java?
- Java Program to change the background color of rows in a JTable

Advertisements