- 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 select all cells in a table
To select all cells in a table in Java Swing, you need to use the selectAll() method. Let’s say the following are our table rows and columns −
String[][] rec = { { "001", "Shirts", "40" }, { "002", "Trousers", "250" }, { "003", "Jeans", "25" }, { "004", "Applicances", "90" }, { "005", "Mobile Phones", "200" }, { "006", "Hard Disk", "150" }, }; String[] header = { "ID", "Product", "Quantity" };
Set it for a table −
JTable table = new JTable(rec, header);
Now select all the rows and columns −
table.selectAll();
The following is an example to select all cells in a table −
Example
package my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Stock", TitledBorder.CENTER, TitledBorder.TOP)); String[][] rec = { { "001", "Shirts", "40" }, { "002", "Trousers", "250" }, { "003", "Jeans", "25" }, { "004", "Applicances", "90" }, { "005", "Mobile Phones", "200" }, { "006", "Hard Disk", "150" }, }; String[] header = { "ID", "Product", "Quantity" }; JTable table = new JTable(rec, header); table.setShowHorizontalLines(true); table.setGridColor(Color.blue); table.selectAll(); panel.add(new JScrollPane(table)); frame.add(panel); frame.setSize(550, 400); frame.setVisible(true); } }
This will produce the following output −
- Related Articles
- Java Program to deselect all cells in a JTable
- Java Program to select all the items in a JList
- How to select different cells of a JTable programmatically in Java?
- How to select all the column names from a table in Laravel?
- Java Program to select a column in JTable?
- How to select all the data from a table using MySQL in Python?
- How to select all distinct filename extensions from a table of filenames in MySQL?
- How to select all rows from a table except the last one in MySQL?
- MySQL select query to select rows from a table that are not in another table?
- How to merge table cells in HTML?
- How to select all the records except a row with certain id from a MySQL table?
- In ABAP, How to select all the data into my internal table using loops?
- How can we write MySQL stored procedure to select all the data from a table?
- How to SELECT all values from a table only once if they're duplicated?
- Java Program to remove all elements from a set in Java

Advertisements