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

 
 


A Polite Boy
Remove JTable row that read txt file records
0 Answer(s)      4 months and 22 days 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!

View Answers









Related Pages:
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
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
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
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
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
txt to cvs format
txt to cvs format  i am writing a simple program that read a text file from one directory and writes an new one in cvs format in another one. I am...; /*this program reads files from inpath and writes them to outpath as a single txt
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
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
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
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
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 delete records from jtabel - Swing AWT
number). also tell me ho to genrate serial number for file records.  Hi... of rows: "+ model.getRowCount()); //Remove last row model.removeRow(4...How to delete records from jtabel  hello I am using jtabel
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
Adding .txt files in a given directory
Adding .txt files in a given directory  I want to read number of XML... tag value as one .txt file in a given directory? I have extracted tag values but plz help me how can I save each body tag as one .txt file and add in a directory
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
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
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
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's rows automatically whenever i have records more than four rows. such as if i have
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 to refresh a jTable On adding or deleting record ....
of records.... and new record should be showed in the jtable in the panel.. Plz sir give...How to refresh a jTable On adding or deleting record ....   Hii Sir, I am developing a project in which a jtable is getting populated
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
jtable
jtable  i have build an application and i retrieve data from the database and store it in jtable.now i have to make a checkbox column in each row and also a select all option in header but i am not able to do so.i am getting
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
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
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
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset using JTable?   JTable is component of java swing toolkit. JTable class is helpful in displaying data in tabular format. You can also edit data. JTable
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
Java Read CSV file
Java Read CSV file In this tutorial, you will learn how to read csv file. CSV (Comma Separated Value) is a common type of data file which can be exported... opened a file data.csv  and created a BufferedReader object to read
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
or .txt) file and get the values from that file and store them into database table in multiple rows(which means one value for one row). eg: my file containes...how to read the values for text and csv files and store those values
Read data again - Java Beginners
), jab varchar(35), cab varchar(15), ket varchar(30) My data in txt file is://i... data from txt file and send to DB.i'm using one button to call.  Hi... = DriverManager.getConnection(url+db,"root","root"); //Read File Line By Line
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
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
JTable - Java Beginners
JTable  Hi, I have some problem with JTable. On show All button hit, I want to show all records on the panel in a table format from ms-sql server. my problem is with Jtable, sometimes it is visible and sometimes it is not. when
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
How to read an eml file? - Java Beginners
How to read an eml file?  Hello dears, now i want to read en eml file stored in a folder. is it possible to use the same code for reading a txt file? or do i have to use javamail api? Thanks Spalax
update a JTable - Java Beginners
update a JTable   how to update a JTable with Mysql data through user... in an updatable JTable You would create the table as follows: conn... = new ResultSetTableModel(rs); table = new JTable(model
Read Write
Read Write  Hi; How can I read certain line of say 10 text files and write to one text file   Java Read Multiple Files and store the data... OnlyExt("txt"); File f=new File("C:/"); File[] files = f.listFiles(ff); for(int i=0
Java file read write operation
Java file read write operation  how to read and write the data from text file.Suppose i have text file with 4 fields name ,roll no ,marks1,marks2 with more than 20 records......i need to store these value in object and pass
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
JTable - Java Beginners
want my JTable on the panel. and i also want to increase height and width...); showbutton=new JButton("Show Records"); sp= new JScrollPane(); sl= new...(md.getColumnName(i)); } while (res2.next()) { Vector row = new
Mysql Alter Remove Column
Mysql Alter Remove Column       Mysql Alter Remove Column is used to redefine the table and remove... an example from 'Mysql Alter Remove Column'. To understand this example we create
JTable - Java Beginners
JButton("Show Records"); sp= new JScrollPane(); sl= new SpringLayout...)); } while (res2.next()) { Vector row = new Vector(columns...(res2.getObject(i)); } data.addElement(row); } res2.close
Read data again - Java Beginners
varchar(15), cab varchar(15), ket varchar(30) then i have a data from txt file... Pusat; i want data from txt file save to database like my DB with one button.but...","root","suprax"); //Read File Line By Line while ((strLine = br.readLine
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 djilepak.javaclss.for
Java swing: Export excel sheet data to JTable
how to read data from excel file and export it to JTable. In swing applications, sometimes, it is required to display the excel file data into the jtable... of the excel and file. Here is the excel file to be read. Example import
jTable data problem
jTable data problem  Hello. I have a code that read file and store... that read file and store in arraylist and then convert to array(To use for table...(){ JFrame frame=new JFrame(); JTable table=new JTable(rftl); JPanel panel

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.