
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can we hide the table header from a JTable in Java?
Yes, we can hide the header from a table. Use the setTableHeader() method and set it to null -
table.setTableHeader(null);
Above, the table is our JTable -
JTable table = new JTable(marks, col)
The following is an example to hide the table header -
Example
package my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.JTableHeader; 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 col[] = { "S1", "S2", "S3", "S4", "S5", "S6"}; JTable table = new JTable(marks, col); Font font = new Font("Verdana", Font.PLAIN, 12); table.setFont(font); table.setRowHeight(30); table.setBackground(Color.blue); table.setForeground(Color.white); table.setTableHeader(null); JFrame frame = new JFrame(); frame.setSize(600, 400); frame.add(new JScrollPane(table)); frame.setVisible(true); } }
Here is the output. We have set a table header above but it won’t be visible since it is set to null afterwards -
Output
- Related Questions & Answers
- How can we show/hide the table header of a JTable in Java?
- How can we remove a selected row from a JTable in Java?
- How can we filter a JTable in Java?
- How can we disable the cell editing inside a JTable in Java?
- How can we implement the word wrap JTableHeader of a JTable in Java?
- How can we prevent the re-ordering columns of a JTable in Java?
- How can we sort a JTable on a particular column in Java?
- How can we show/hide the echo character of a JPasswordField in Java?
- How can we add/insert a JButton to JTable cell in Java?
- How can we detect the double click events of a JTable row in Java?
- How to change JTable's header font in Java
- How can we add/insert a JCheckBox inside a JTable cell in Java?
- How can we add/insert a JRadioButton to a JTable cell in Java?
- How can we create a table from an existing MySQL table in the database?
- Can we add a column to a table from another table in MySQL?
Advertisements