- 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 display both horizontal and vertical grid lines in a JTable
To display both horizontal and vertical grid lines in a table, use the setShowGrid() method and set it to true −
table.setShowGrid(true);
The following is an example to display both horizonal and vertical grid lines in a JTable −
Example
package my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class SwingDemo { public static void main(String[] argv) throws Exception { Integer[][] marks = { { 70, 66, 76, 89, 67, 98 }, { 67, 89, 64, 78, 59, 78 }, { 68, 87, 71, 65, 87, 86 }, { 80, 56, 89, 98, 59, 56 }, { 75, 95, 90, 73, 57, 79 }, { 69, 49, 56, 78, 76, 77 } }; String students[] = { "S1", "S2", "S3", "S4", "S5", "S6"}; JTable table = new JTable(marks, students); Font font = new Font("Verdana", Font.PLAIN, 12); table.setFont(font); table.setRowHeight(30); table.setGridColor(Color.yellow); table.setShowGrid(true); JFrame frame = new JFrame(); frame.setSize(600, 400); frame.add(new JScrollPane(table)); frame.setVisible(true); } }
Output
- Related Articles
- Java Program to display only vertical grid lines in a JTable
- Java Program to display only horizontal grid lines in a JTable
- How to display horizontal grid lines in a JTable with Java?
- How to display vertical grid lines in a table with Java?
- How to prevent displaying any grid lines in a JTable?
- Plot horizontal and vertical lines passing through a point that is an intersection point of two lines in Matplotlib
- Bootstrap Grid Stacked to horizontal grid
- Distribute extra horizontal and vertical space in a GridBagLayout with Java
- Disable auto resizing to make the JTable horizontal scrollable in Java
- What letters of the English alphabet have reflectional symmetry $(i.e.,\ symmetry\ related\ to\ mirror\ reflection)$ about.$(a)$. a vertical mirror$(b)$. a horizontal mirror$(c)$. both horizontal and vertical mirrors
- Java Program to select a column in JTable?
- How to display the vertical and horizontal scrollbars always even if it is not required
- Java Program to append a row to a JTable in Java Swing
- Stacked-to-horizontal Bootstrap Grid
- Java Program to enable cell selection in a JTable

Advertisements