How do i delete multiple rows in JTable

hello
how i delete multiple rows in JTable
when i selected multiple rows from the jtable and delete its give the error ArrayIndexOutOfBoundException
e.g.
int rows[]=jtable.getSelectedRows();
for(int i=0;i<rows.length;i++)
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
model.removeRow(rows);
like this
please help me
meraj

You are trying to remove the rows an equal times to the amount of rows selected.
You should remove one row at a time:
model.removeRow(rows);
Change your code into this.
for(int i=0;i<rows.length;i++)
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
model.removeRow(rows[i]);

Similar Messages

  • Delete Multiple Rows of JTable by selecting JCheckboxes

    Hi,
    I want delete rows of JTable that i select through JCheckbox on clicking on JButton. The code that i am using is deleting one row at a time. I want to delete multiple rows at a time on clicking on Button.
    This is the code i m using
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableTest extends JFrame implements ActionListener
         JButton btnAdd;
         BorderLayout layout;
         DefaultTableModel model;
         JTable table;JButton btexcluir;
         public static void main(String[] args)
              TableTest app = new TableTest();
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TableTest()
              super("Table Example");
              btnAdd = new JButton("Add");
              btnAdd.addActionListener(this);
              model = new DefaultTableModel()
                   public Class getColumnClass(int col)
                        switch (col)
                             case 1 :
                                  return Boolean.class;
                             default :
                                  return Object.class;
              table = new JTable(model);
              table.setPreferredSize(new Dimension(250,200));
              // Create a couple of columns
              model.addColumn("Col1");
              model.addColumn("Col2");
              JCheckBox cbox = new JCheckBox();
              // Append a row
              JPanel painel = new JPanel();
              model.addRow(new Object[] { "v1",new Boolean(false)});
              model.addRow(new Object[] { "v3", new Boolean(false)});
              JScrollPane scrollPane = new JScrollPane(table);
              scrollPane.createVerticalScrollBar();
              btexcluir= new JButton("Excluir");
              btexcluir.addActionListener(this);
              painel.add(btexcluir);
              painel.add(btnAdd);
              getContentPane().add(scrollPane, BorderLayout.NORTH);
              getContentPane().add(painel, BorderLayout.SOUTH);
              setSize(600, 600);
              setVisible(true);
         public void actionPerformed(ActionEvent e)     {
           if (e.getSource() == btnAdd)     
              model.addRow(new Object[] { "Karl", new Boolean(false)});
           if (e.getSource()==btexcluir){
                for (int i=0; i <=model.getRowCount(); i++){
                     if (model.getValueAt(i,1)==Boolean.FALSE)
                          JOptionPane.showMessageDialog(null, "No lines to remove!!");
                     else if(model.getValueAt(i,1)==Boolean.TRUE)
                          model.removeRow(i);
    }Please reply me with code help.
    Thanks
    Nitin

    Hi,
    Thanks for ur support. My that problem is solved now. One more problem now . Initially i want that delete button disabled. When i select any checkbox that button should get enabled. how can i do that ?
    Thanks
    Nitin

  • How do I delete multiple rows and columns in an image?

    I am looking into how digital SLRs extract video data from a CMOS sensor. To give an example, the GH1 from Panasonic can record video at 1920 x 1080 from a 12 MPixel sensor that, say, is 4000 horizontal x 3000 vertical. How they do that seems to be not in the public domain, but there have been a few guesses (see http://www.dvxuser.com/V6/showthread.php?t=206797 and http://luminous-landscape.com/forum/index.php?showtopic=38713).
    One approach would be to simply read every second row of sensor pixels (1500 rows read from the original 3000) and once you have those in memory, delete every second column (2000 columns left). You would end up with a 2000 x 1500 image which could then be resampled to 1920 x 1080.
    I'd like to simulate what the camera appears to be doing, by generating a 4000 x 3000 test image and then asking Photoshop CS4 to delete the appropriate rows and columns. It may not necessarily be every second row; the Canon 5DMk11 appears to read every third row, so I may need to delete two out of every three rows.
    Can Photoshop do that sort of thing? If so, how?

    Thanks for the suggestions. Yes, I did take a detailed look at your images, but they weren't 100% convincing because it wasn't clear just what was happening. And Adobe's explanation, after reading it again, explains nothing at all to someone who doesn't know how Nearest Neighbor works.
    But you are correct -- Nearest Neighbor does effectively delete pixels. I proved it with the attached 6 x 6 image of coloured pixels (the tiny midget image right after this full stop -- you'll have to go to maximum zoom in PS to see it).
    These are the steps to delete every second row and then every second column.
    1. Select Image > Image Size.
    2. Set Pixel Dimensions > Height to half the original (in this case set to 3 pixels).
    3. Set Resample Image to Nearest Neighbor.
    4. Click OK and the image shoould now consist of three vertical white strips and three vertical Green-Red-Blue stripes.
    5. Repeat steps 1-4, but this time set Pixel Dimensions > Width to half the original (in this case set to 3 pixels). The image should now consist of three horizontal stripes Green-Red-Blue.
    Just to make sure the method worked for every third pixel, I repeated the above steps but with 2 pixels instead of 3 and obtained the correct White-Green, White-Green pattern.
    I resampled the Height and Width separately for the test so that I could see what was happening. In a real example, the height and width can be changed at the same time in the one step, achieving the same results as above.
    Finally, how to explain how Nearest Neighbor works in the simple cases described above?
    Division by 2
    In the case of an exact division by two (pixels numbered from top leftmost pixel), only the even numbered rows and columns remain. To put it a different way, every odd numbered row and column are deleted.
    Division by 3
    Only rows and columns 2, 5, 8, 11... remain.
    Division by N
    Only rows and columns 2, 2+N, 2+2N, 2+3N... remain.
    To put it simply, a resample using Nearest Neighbor (using an exact integer multiple) keeps every Nth row and column, starting from number two. The rest are deleted.

  • Delete multiple rows in jtable

    here's what i want to do
    let user select the rows themselves and then when they press delete button, the rows that they select are removed
    however, I do not have any idea on how to go about doing that though, like how do I get the selection value (sometimes it may be one whole chunk, sometimes it might be at different places altogether)

    but the problem comes in after sorting the row;Are we supposed to be mind readers? How where we supposed to guess that the problem was related to sorting based on your original question. Learn to ask a proper question so you don't waste our time.
    Anyway you still haven't given us enough information to help you.
    Are you using the sorting feature of JDK6, in which case the API has methods that allow you to convert the "view" row to the "model" row. So I suggest you read the API.

  • How do I delete multiple rows from datagrid?

    Hi,
    I have a datagrid which has an item renderer on the 1st column which displays a checkbox. I wish to delete all the rows of data from my datagrid which have the checkbox selected.
    I'd be very grateful if anyone can anyone help me with this.
    Thanks in advance,
    Xander

    Test this:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="vertical" xmlns:components="components.*">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var dp:ArrayCollection;
                private function init():void
                    var sa:Array = [{selected: false, value: "Some value"}, {selected: true, value: "Some other value"}];
                    dp = new ArrayCollection(sa);
                private function handleDelete():void
                    var na:Array = dp.source.filter(function callback(item:*, index:int, array:Array):Boolean
                                return item.selected == false;
                    dp.source = na;
            ]]>
        </mx:Script>
        <mx:DataGrid dataProvider="{dp}">
            <mx:columns>
                <mx:DataGridColumn headerText="Column 1" dataField="selected">
                    <mx:itemRenderer>
                        <mx:Component>
                            <mx:CheckBox selected="{data.selected}" click="data.selected = event.target.selected"/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>
                <mx:DataGridColumn headerText="Column 2" dataField="value"/>
            </mx:columns>
        </mx:DataGrid>
        <mx:Button label="Delete selected" click="handleDelete()"/>
    </mx:Application>
    Dany

  • Delete multiple rows in a JTable ADF Swing.

    hi guys,
    Would anyone know tell me how do I delete multiple rows in a JTable ADF Swing?
    JDeveloper.

    Hi,
    I would configure the table for multi row selection. Then get the selected row index, access the iterator in the PageDef file (through the panelBinding reference you have in ADF Swing) and then iterate over the selected row indexes, make an index to become the current row and call remove() on it
    Frank

  • Best practice for deleting multiple rows from a table , using creator

    Hi
    Thank you for reading my post.
    what is best practive for deleting multiple rows from a table using rowSet ?
    for example how i can execute something like
    delete from table1 where field1= ? and field2 =?
    Thank you

    Hi,
    Please go through the AppModel application which is available at: http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    The OnePage Table Based example shows exactly how to use deleting multiple rows from a datatable...
    Hope this helps.
    Thanks,
    RK.

  • How to delete multiple rows from ADF table

    How to delete multiple rows from ADF table

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • Updating and deleting multiple rows

    Hi!
    I have a form on a table with report page where I can filter data through columns.
    1. Is it possible to create a button that will delete all the filtered data?
    2. Also, I would like to be able to update any column of the filtered dataset to a certain value (that needs to be input somehow). Is that possible?
    So far I can only update or delete one row at a time, which isn't useful as I sometimes need to change 100 rows at a time with the same value or delete them.
    When I use tabular form, I can't filter rows, but I can delete multiple rows...
    Also if there are similar examples, could you please send me a link; I can't seem to find any.
    I'm using Apex 4.2.2.
    Best Regards,
    Ivan

    Deleting multiple rows - [url https://forums.oracle.com/forums/thread.jspa?threadID=2159983]common question
    Best answered with Martin's example
    http://www.talkapex.com/2009/01/apex-report-with-checkboxes-advanced.html
    Depends how you filter your data. You could identify all your limiting variables, and reverse the where clause in a delete process.
    As for point 2, you can define a button that redirects to the page, and you can defined all the item values you like using the Action link.
    There is likely an example in the supplied package applications.
    Scott

  • Deleting Multiple Rows From Multiple Tables As an APEX Process

    Hi There,
    I'm interesting in hearing best practice approaches for deleting multiple rows from multiple tables from a single button click in an APEX application. I'm using 3.0.1.008
    On my APEX page I have a Select list displaying all the Payments made and a user can view individual payments by selecting a Payment from the Select List (individual items are displayed below using Text Field (Disabled, saves state) items with a source of Database Column).
    A Payment is to be deleted by selecting a custom image (Delete Payments Button) displayed in a Vertical Images List on the same page. The Target is set as the same page and I gave the Request a name of DELETEPAY.
    What I tried to implement was creating a Conditional Process On Submit - After Computations and Validations that has a source of a PL/SQL anonymous block as follows:
    BEGIN
    UPDATE tblDebitNotes d
    SET d.Paid = 0
    WHERE 1=1
    AND d.DebitNoteID = :P7_DEBITNOTEID;
    INSERT INTO tblDeletedPayments
    ( PaymentID,
    DebitNoteID,
    Amount,
    Date_A,
    SupplierRef,
    Description
    VALUES
    ( :P7_PAYMENTID,
    :P7_DEBITNOTEID,
    :P7_PAID,
    SYSDATE,
    :P7_SUPPLIERREF,
    :P7_DESCRIPTION
    DELETE FROM tblPayments
    WHERE 1=1
    AND PaymentID = :P7_PAYMENTID;
    END;
    The Condition Type used was Request = Expression 1 where Expression 1 had a value of DELETEPAY
    However this process is not doing anything!! Any insights greatly appreciated.
    Many thanks,
    Gary.

    ...the "button" is using a page level Target,...
    I'm not sure what that means. If the target is specified in the definition of a list item, then clicking on the image will simply redirect to that URL. You must cause the page to be submitted instead, perhaps by making the URL a reference to the javaScript doSubmit function that is part of the standard library shipped with Application Express. Take a look at a Standard Tab on a sample application and see how it submits the page using doSubmit() and emulate that.
    Scott

  • Deleting multiple rows in a report ?

    db11gxe  , apex 4.0 , firefox 24 ,
    how to delete multiple rows in a report at one time ?
    thanks

    Hi newbi_egy,
    Here is a small demo with few steps that can be used in your scenario-
    1) Below is the query of a report on emp table which has empno column with unique values-
    SELECT APEX_ITEM.CHECKBOX(1,empno) " ", ename, job FROM   emp ORDER  by 1
    2) A Delete button is created that submits the page.
    3) An on-submit process is created with Process point On Submit - After Computation and Validations with condition that the below process runs when Delete button clicked.
    BEGIN
    FOR i in 1..APEX_APPLICATION.G_F01.count
    LOOP
    delete from emp where empno=APEX_APPLICATION.G_F01(i);
    END LOOP;
    END;
    I hope this might help you.
    Regards,
    Das123

  • Adding and Deleting Multiple Rows or Columns

    How do you add or delete more than one row or column at a time.

    Robby! wrote:
    That's a great finding!
    I just wrote a feedback requesting a shortcut like this.
    It is a pity though that they desing it to work only if you select the header of the row/column. It should be enabled to work from within any cell in the table.
    Who wrote such an error ?
    These interesting shortcuts behave flawlessly even if the cursor was in D18 for instance.
    (a) I never saw them in the delivered resources.
    (b) they aren't responding to the OP's question which was about "Adding and Deleting Multiple Rows and Columns"
    Yvan KOENIG (from FRANCE vendredi 3 octobre 2008 18:39:01)

  • How do you delete multiple emails from your "inbox" w/o clicking on each one individually?

    How do you delete multiple inbox emails to trash w/o clicking on each one individually?

    Highlight one. Click edit. Click "mark all" at the bottom. Click trash.
    Barry

  • How do I delete multiple items at once instead of one at a time?

    How do I delete multiple items at once instead of one at a time? I have several duplicate items in my library and would like to delete the duplicates. Thanks!

    You can select multiple items using shift to select a range and control to add or remove items from it.
    Regarding duplciates, Apple's official advice is here... HT2905 - How to find and remove duplicate items in your iTunes library. It is a manual process and the article fails to explain some of the potential pitfalls.
    Use Shift > View > Show Exact Duplicate Items to display duplicates as this is normally a more useful selection. You need to manually select all but one of each group of identical tracks to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks, however this works best when performed immediately after the dupes have been created.  If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin. This can happen, for example, if you start iTunes with a disconnected external drive, then connect it, reimport from your media folder, then restart iTunes.
    Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background. Please take note of the warning to backup your library before deduping, whether you do so by hand or using my script, in case something goes wrong.
    (If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
    tt2

  • How do i delete  multiple emails at one time from iphone Mail account with iphone 4s?

    how do i delete  multiple emails at one time from iphone Mail account with iphone 4s?

    Better than that!
    http://www.youtube.com/watch?v=fKa-KFjUIGE
    Select a message, hold the move button, deselect the message while still holding the move button.
    A new window appears allowing you to move all messages to the trash.
    Bingo!

Maybe you are looking for

  • Problem with extended SQL functions in RTF Template

    Hello, I'm new to BI Publisher and I'm trying to create a new rtf template. I've created my layout and added fields without any problems, but I'm having trouble trying to insert calculations such as add,substract,multiply,divide, etc. Here is an exam

  • Error while Posting Excise JV

    Hi, While Posting Excise JV through J1IH,J2IUN, transaction code we are getting following error "Error in FI Document create" Thanks in advance Samir Joshi

  • Document Splitting with Different Business Area

    HI I have a situation, where i need to create a new document type and it needs to be configured in such a way that vendor invoices and credit notes can be booked with the correct doc splitting and using different Business Areas. I like to know if thi

  • Two FIOS boxes in the same room, remote issues

    I have two cable boxes in my living room to enjoy the football season.  my only problem is that all fios boxes have the saem remote settings.  Does any one know a way to get the two boxes working separately for under 100 bucks?

  • Sybase datetime col...how to generate as timestamp col in oracle ddl

    i'm having trouble understanding the date mapping... i'm taking the defaults (per http://dermotoneill.blogspot.com/2008/06/offline-data-move-dates.html)... but my sybase datetime columns are being generated as date columns in the oracle ddl. (so i lo