Remove JTable row that read txt file records

Remove JTable row that read txt file records

Hi every one. i have a jtable that correctly read data frome file and show them in own. I want to add a "Delete" button that when select a row and clicked button, row must deleted. But, when i click the button, row dont deleted and a ArrayOutOutBoundsException occur.

my whole code is this:

    import java.awt.event.ActionEvent;  
    import java.awt.event.ActionListener;  
    import java.io.BufferedReader;  
    import java.io.FileInputStream;  
    import java.io.InputStreamReader;  
    import java.util.StringTokenizer;  
    import java.util.Vector;  
    import javax.swing.JButton;  
    import javax.swing.JFrame;  
    import javax.swing.JPanel;  
    import javax.swing.JScrollPane;  
    import javax.swing.JTable;  
    import javax.swing.table.AbstractTableModel;  

    public class RemoveRow extends AbstractTableModel{  

    Vector data;  
    Vector columns;  
    public RemoveRow() {  

            String line;  
            data = new Vector();  
            columns = new Vector();  
            try {  
            FileInputStream fis = new FileInputStream("D:\\AllUserRecords.txt");  
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));  
          StringTokenizer st1 = new StringTokenizer(br.readLine(), " ");  
                  while (st1.hasMoreTokens())  
                   columns.addElement(st1.nextToken());  
                    while ((line = br.readLine()) != null) {  
                           StringTokenizer st2 = new StringTokenizer(line, " ");  
                            while (st2.hasMoreTokens())  
                                    data.addElement(st2.nextToken());  
                    }  
                    br.close();  
            } catch (Exception e) {  
                    e.printStackTrace();  
            }  
    }  

        public int getRowCount() {  
            return data.size() / getColumnCount();  
    }  

    public int getColumnCount() {  
            return columns.size();  
    }  

    public Object getValueAt(int rowIndex, int columnIndex) {  
            return (String) data.elementAt((rowIndex * getColumnCount())  
                            + columnIndex);  
    }  
    public static void main(String[] args){  

        final RemoveRow rR1=new RemoveRow();  
        JFrame frame=new JFrame();  
        final JTable table=new JTable();  
        table.setModel(rR1);  
        JPanel panel=new JPanel();  
        JButton button1=new JButton("Delete");  

        button1.addActionListener(new ActionListener() {  

                public void actionPerformed(ActionEvent e) {                 
                    table.remove(table.getSelectedRow());  
                }  
            });  
            panel.add(button1);  
            panel.add(new JScrollPane(table));  
            frame.add(panel);  
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
            frame.setBounds(10, 10, 600, 300);  
            frame.setVisible(true);  
    }  

    }

please repair my code!

Thanks!

View Answers









Related Tutorials/Questions & Answers:
Remove JTable row that read txt file records
Remove JTable row that read txt file records  Hi every one. i have a jtable that correctly read data frome file and show them in own. I want to add a "Delete" button that when select a row and clicked button, row must deleted
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
How to read and retrieve jtable row values into jtextfield on clicking... application in which i have to display database records in jtable .now I want to read all the values of particular row at which mouse is clicked. and display
Advertisements
Backup selected records into txt file
Backup selected records into txt file       Backup selected records into txt file is used to copies... Selected records into txt file. To restore the selected backup records into txt
Backup selected records into txt file
Backup selected records into txt file       Backup selected records into txt file is used... a Example from Backup Selected records into txt file. To restore the selected backup
how to read text file in jtable in netbeans7.0
how to read text file in jtable in netbeans7.0  text file is: contig00001 length=586 numreads=4... want to displaythe above .txt file in jtable as following format having 3
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
Removing a Row from a JTable
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... Removing a Row from a JTable     
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project for pharmacy .. *pblm:* when i want to enter the details in jtable while running... to add one more row dynamically as a new row 4th if the details are large.but every
Java: Adding Row in JTable
Java: Adding Row in JTable   how about if we already have the JTAble created earlier. And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method. Is there any work around for this? I found
Thread for reading txt file
Thread for reading txt file  how to use 3 thread to read 3 txt file? To create three threads for reading the file and three threads for getting the strings out of the queue and printing them. thanks
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data... this. Thank's very much   Hi friend, code to read a file import
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
Backup Into txt File
Backup Into txt File       Backup Into txt File is used to put the backup file from a ... The Tutorial illustrate an example from 'Backup Into txt File
ModuleNotFoundError: No module named 'file_open_gips_txt'
named 'file_open_gips_txt' How to remove the ModuleNotFoundError: No module named 'file_open_gips_txt' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'file_open_gips_txt'  Hi, My
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
Extract File data into JTable
Extract File data into JTable In this section, you will learn how to read the data from the text file and insert it into JTable. For this, we have created... the BufferedReader class, we have read the data of the file. This data is then broken
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djile pak.java
Backup Into txt File
Backup Into txt File       Backup Into txt File is used to put the backup file from..._TO_REPLACE_1 The Tutorial illustrate an example from 'Backup Into txt File
read a file
read a file  read a file byte by byte   import java.io.File..._TO_REPLACE_1 public static void main(String[] args) { File file = new File("D://Try.txt"); try { FileInputStream fin = new FileInputStream(file
Need to Remove Duplicate Records from Excel Sheet
Need to Remove Duplicate Records from Excel Sheet  Need to Remove Duplicate Records from Excel Sheet. I have one excel sheet having two fields... empnum rating (without using sql query have to remove records from excel using java
file read
file read  hi i am reaing from a file which has punjabi words. can some one help with me some code
CONVERT JTable DATA TO PDF FILE
the jtable data from the jframe and stored the data into the pdf file in the form...(JTable table, int row_index, int col_index){ return table.getModel().getValueAt...CONVERT JTable DATA TO PDF FILE  HOW TO CONVERT JTable DATA TO .PDF
convert .txt file in .csv format - Java Beginners
convert .txt file in .csv format  Dear all, I hope you are doing good. I am looking to convert .txt file in .csv format. The contents might have... want export these contents to a .csv file. I am aware that I need to use
how to change file from .txt to .mat(matrix)
how to change file from .txt to .mat(matrix)  i have a big file.txt and i want to change this file to file.mat(matrix) ...this is in windows not on any os ..thx if u answering quickly please
Shifting txt file to database - Java Beginners
Shifting txt file to database   Question Details: I want to shift data from txt file to Database. The data is written in the following text format. Record No. = 0001 Name : Abdul Rauf Designation
reading the records from a .xlsx file and storing those records in database table
reading the records from a .xlsx file and storing those records in database table  Here is my requirement, I want to read the records from a .xlsx file and store that records in database table. I tried like this public class
Enabling Row, Column and Cell Selections in a JTable
Enabling Row, Column and Cell Selections in a JTable... to describe how to enable the row, column and cell selections in a JTable... will see the enabling row, column and cell selections in a JTable. When you
How to import txt file using SQL
How to import txt file using SQL  Hai, I have a log file in .txt format and format of the log is given below. From the log i want to pick up some particular words and insert onto a table using SQL. I want the output of the table
Access Excel file through JDBC
Access Excel file through JDBC In this section, you will learn how to access excel file through Jdbc and display records in JTable. As you know Excel comes... and the excel file. Here the name of the worksheet is equivalent to any database
java jtable
in which i have to display database records in jtable .now I want to read only the values of particular row at which the jtextfield has been set. and display that in jtable. plz help me with the code
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Read and write file
Read and write file  HI, How to read and write file from Java program? Thanks   Hi, See the following tutorials: Java Write To File Read File Thanks
Read external file in PHP
Read external file in PHP  How to read external files in PHP in particular time duration and save that file with the latest date. How is it possible? Please explain with an example. Thanks
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Java read binary file
Java read binary file  I want Java read binary file example code that is easy to read and learn. Thanks   Hi, Please see the code at Reading binary file into byte array in Java. Thanks   Hi, There is many
Read Video File
Read Video File  how to read a video file, after that i want to encrypt and decrypt it. please help me and if u can send me some hint or source code on [email protected] Thanks & Regards Swarit Agarwal
Read the file Contents
Read the file Contents  Ravi Raj,Vijay45Shankar,234 Guna,345,Meet me,654,Cow Read file contents and Print the no.of words and Numbers./p> Thanks, Dinesh Ram   The given code read the file content and print
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class EncryptionWithCertificate { public
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class EncryptionWithCertificate
Java insert file data to JTable
Java insert file data to JTable In this section, you will learn how to insert text file data into JTable. Swing has provide useful and sophisticated set... with AbstractTableModel to inherit its methods and properties. Now we have read the file
reading a csv file from a particular row
reading a csv file from a particular row  how to read a csv file from a particular row and storing data to sql server by using jsp servlet
Java convert jtable data to pdf file
Java convert jtable data to pdf file In this tutorial, you will learn how to convert jtable data to pdf file. Here is an example where we have created... have fetched the data from the jtable and save the data to pdf file. Example
storing records which of a file into a table of mssql database
storing records which of a file into a table of mssql database  I have a requirement like this, A file contains some records with headers same as column names of a table. I have to store those records into a table
Writing Log Records to a Log File
Writing Log Records to a Log File   ... and severe that have log records. Log records are written into a log file... is exist then log records will be written into a log file and it displays
Java Read CSV file
Java Read CSV file In this tutorial, you will learn how to read csv file. CSV... opened a file data.csv  and created a BufferedReader object to read...{ int row = 0; int col = 0; String[][] numbers=new String[24][24]; File file
how to sort the text file and display it in jtable
how to sort the text file and display it in jtable   my text file is: contig00001 length=586 numreads=4... in jtable and sequence like "CGGGAATTAA..." in jtextarea in netbeans . pls suggest
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file

Ads