Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Remove JTable row that read txt file records
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


A Polite Boy
Remove JTable row that read txt file records
0 Answer(s)      a year and 8 months ago
Posted in : Java Beginners


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!


Advertisement
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
Backup selected records into txt file
Backup selected records into txt file       Backup selected records into txt file is used to copies... into txt file. To restore the selected backup records into txt file, we create
Advertisements
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
Backup selected records into txt file
Backup selected records into txt file       Backup selected records into txt file is used... Selected records into txt file. To restore the selected backup records into txt
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
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
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     
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
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
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
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
Backup Into txt File
Backup Into txt File       Backup Into txt File is used to put the backup file from a ... illustrate an example from 'Backup Into txt File'. To understand this example
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
Backup Into txt File
Backup Into txt File       Backup Into txt File is used to put the backup file from... The Tutorial illustrate an example from 'Backup Into txt 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
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
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
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
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
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
read a file
read a file  read a file byte by byte   import java.io.File... static void main(String[] args) { File file = new File("D://Try.txt"); try { FileInputStream fin = new FileInputStream(file); byte
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
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
How to select only .txt file to be zipped using java?
How to select only .txt file to be zipped using java?  Hello, i'm trying to zipp .txt files from a folder but i want to know how to select only .txt...() { public boolean accept(File dir, String name) { return !name.startsWith(".txt
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
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
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
 

 

 

DMCA.com