- 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
Move the first row to the end of the JTable in Java Swing
To move the first row to the end of the table in Java, use the moveRow() method. It has three parameters. The first two parameters allows you to set the starting and ending row index to be moved. The last parameter sets the destination of the rows to be moved.
As discussed above, move the first row to the end −
tableModel.moveRow(0, 0, tableModel.getRowCount() - 1);
The following is an example to move the first row to the end of the 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("Difficulty Level"); tableModel.addRow(new Object[] { "AngularJS", "Difficult"}); tableModel.addRow(new Object[] { "CSS", "Easy" }); tableModel.addRow(new Object[] { "HTML5", "Easy"}); tableModel.addRow(new Object[] { "JavaScript", "Intermediate" }); tableModel.addRow(new Object[] { "jQuery", "Intermediate" }); tableModel.addRow(new Object[] { "WordPress", "Easy" }); table.setRowHeight(table.getRowHeight() + 5); // move first row to the end of the table tableModel.moveRow(0, 0, tableModel.getRowCount() - 1); JFrame f = new JFrame(); f.setSize(550, 350); f.add(new JScrollPane(table)); f.setVisible(true); } }
The output is as follows. Here, we have moved the first row (“AngularJS”, “Difficulty”) to the end −
- Related Articles
- Java Program to append a row to a JTable in Java Swing
- How to add a new row to JTable with insertRow() in Java Swing
- Move All the Zeros to the End of Array in Java
- How to add JTable to Panel in Java Swing?
- How to move the ResultSet cursor to the first row in JDBC?
- How to get the number of rows and columns of a JTable in Java Swing
- Java Program to increase the row height in a JTable
- How to add a title to JTable in Java Swing?
- Double the first element and move zero to end in C++ Program
- How to select the first column in a JTable with Java?
- How to apply adjustments to the next column of a JTable only, when the width of a column is changed in Java Swing?
- How to apply adjustments to the last column of a JTable only, when the width of any column is changed in Java Swing?
- How to display row count in Java Swing JList
- Move first element to end of a given Linked List in C++
- Python Program to move numbers to the end of the string

Advertisements