Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Removing a Row from a JTable

                         

After inserting the data in a JTable, if you wish to remove any one row's data that is wrong entry then you must have to remove from the JTable. For removing the data of row from JTable, you will remove it from its table model. An implementation of DefaultTableModel that supports the removal data of row.  Here providing you an example with code that removes some rows from a table.

Description of program:

This program creates a table with some data by using the DefaultTableModel that helps us for removing the data of row from a table. The removeRow() method is used to remove data at the specified index of row that have to removed from a table. Here the data of first and last rows are deleted by using the removeRow method. The following output will represent to it so, you will easily understood about it.

Description of code:

removeRow( int row_index ):
This method is used to remove the row from the model. It takes integer type row index that means its position or location in a table.

    row_index: This is the index of row that have to removed.

Here is the code of program:

import javax.swing.*;
import javax.swing.table.*;

public class RemoveRows{
  public static void main(String[] args) {
    new RemoveRows();
  }

  public RemoveRows(){
    JFrame frame = new JFrame("Inserting rows in the table!");
    JPanel panel = new JPanel();
    String data[][] {{"Vinod","100"},{"Raju","200"},{"Ranju","300"},
     {
"Rahul","400"},{"Noor","600"}};
    String col[] {"Name","code"};
    DefaultTableModel model = new DefaultTableModel(data,col);
    JTable table = new JTable(model);
    System.out.println("Befoure removing, number of rows: " 
          
+ model.getRowCount());
    //Remove first row
    model.removeRow(0);
    System.out.println("After removing first row, number of rows: " 
           + model.getRowCount
());
    //Remove lase row
    model.removeRow(table.getRowCount()-1);
    System.out.println("After removing last row, number of rows: " 
         
+ table.getRowCount());
    panel.add(table);
    frame.add(panel);
    frame.setSize(300,300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Output of program:

Before removing rows:

After removing rows:

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi,
This code is useful, but suppossing I am choosing a random value for the removal criteria and when the table is connected to a database.
Then how do i modify this code.
This is Urgent!!!
Thanks

Posted by Shivram on Thursday, 05.15.08 @ 13:00pm | #60015

plz give me code of span two cells of table
plz

Posted by arun on Thursday, 12.20.07 @ 12:13pm | #43085

Latest Searches:
overriding
getter setter methods
create text file using
create .csv file using
Display name of system
ASP Form Processing Im
hql date
java example program t
prime numbers between
nested logic
Servlet Container
treemap
log4j
example of JFileChoos
using jacob.jar in jsp
jsp bean get property
adding hibernate tools
Convert Integer to Dou
Struts 2 Validation Ex
java code to insert da
list iteration in java
invalidate()ethode
open close session
form bean
difference b/w pass by
lucene in windows
Integer class
array java
JBI
TextArea Frame in Java
Integer.parseInt examp
parse a int to string
Vector
unix commands in shell
hibernate connection p
CVS Eclipse
Servlet Datasource res
jasper report
struts2 <global-forwar
ASP File Manipulation
modified
Integer.parseInt examp
Hibernate with DAO
create jsp tag
Hospital UML diagrams
Uploading File, Jsf
Eclipse 3.4 EJB
to use java class in j
create txt file in spe
How to get data from d
calculator example
tiles-def.tld
getting xml sub elemen
netbeans jsp
Ajax Login Example
ejb project
Jdk 1.5
Multiplication of Two
intranet applications
PHP Creating a Mail Fo
sending a mail through
sqlserver2000
Photoshop Basics Kodak
java string
input values from cmd
how to save JDBC Conne
ASP Form Processing Se
create csv
Open Source Email Serv
program in java to dis
jsf set href
show folder contents
count line
what is rfc
Java example program t
Jenia pop up jsf
JConfig
SAX
java mail
how to print arraylist
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.