- 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
How to prevent displaying any grid lines in a JTable?
Let’s say the following is our table −
String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" }; JTable table = new JTable(rec, header);
Prevent displaying grid lines −
table.setShowGrid(false);
The following is an example to prevent displaying grid lines −
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(), "ODI Rankings", TitledBorder.CENTER, TitledBorder.TOP)); String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" }; JTable table = new JTable(rec, header); table.setShowHorizontalLines(true); table.setGridColor(Color.orange); table.setRowSelectionAllowed(true); table.setShowGrid(false); panel.add(new JScrollPane(table)); frame.add(panel); frame.setSize(550, 400); frame.setVisible(true); } }
Output
- Related Articles
- How to display horizontal grid lines in a JTable with Java?
- 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 display both horizontal and vertical grid lines in a JTable
- How to prevent resizing columns in a JTable
- How to display vertical grid lines in a table with Java?
- How to make custom grid lines in Seaborn heatmap?
- How can we prevent the re-ordering columns of a JTable in Java?
- CSS Grid Lines
- How to draw grid lines behind Matplotlib bar graph?
- How to remove grid lines from an image in Python Matplotlib?
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- How Can I Prevent Word Breaking Into Different Lines in HTML Table
- How to get rid of grid lines when plotting with Seaborn + Pandas with secondary_y?
- How to add a title to JTable in Java Swing?

Advertisements