- 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 set the height of only a single row in a JTable with multiple rows
To set the row height, use the setRowHeight and set a parameter that would be the number of pixels you need to set the row height.
However, if you want to set the row height of a single row then you need to use the same method, but set an additional parameter as shown below −
table.setRowHeight(3, 30);
The above sets row height to 30 pixels for row index 4.
The following is an example to set the height of a row in a 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[] { "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"}); 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"}); table.setRowHeight(3, 30); JFrame f = new JFrame(); f.setSize(600, 400); f.add(new JScrollPane(table)); f.setVisible(true); } }
The output is as follows. Here, we have set the row height for row 4 −
Output
- Related Articles
- Java Program to set different height for multiple rows in JTable
- Java Program to increase the row height in a JTable
- Return only a single row from duplicate rows with MySQL
- Concatenate multiple rows and columns in a single row with MySQL
- How to set the Row Height of a JTree with Java?
- Java Program to append a row to a JTable in Java Swing
- Java Program to change the background color of rows in a JTable
- How to multiply row values in a data frame having multiple rows with single row data frame in R?
- How to set the color to alternate rows of JTable in Java?
- Count multiple rows and display the result in different columns (and a single row) with MySQL
- How to enable row selection 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
- How to add a new row to JTable with insertRow() in Java Swing
- How to set a value in a particular JTable cell with Java?

Advertisements