Results 1 to 5 of 5
  1. #1
    madcloud is offline Member
    Join Date
    Dec 2010
    Posts
    9
    Rep Power
    0

    Default IndexOutOfBoundsException when jDialog.setVisible(true)

    Hi all,

    I have a desktop application connected to a database created with netbeans. I have 2 tables. One with customers and one with bankchecks. To add a customer the user hits the new button and a jDialog appears that allows him to complete the customer properties and it syncs with the database and mainly it works! When I try to use the same tactic for the bankcheck I get an IndexOutOfBoundsException when setting the jDialog visible to true.

    I believe it has to do with displaying the new record on the table but I m not sure why it throws the error when setting the dialog to true. The dialog is initialised correctly and the table as well as the list have the correct size. If I ignore the error and continue the process of inserting the record and save it, the graphics seem to be stack and it does not repaints them but when I restart the application the record is displayed correctly. Another thing I noticed is that if I delete first a record from the bankcheck and then add a new one, it has no problem with it.

    Here is the code that runs when hitting the new button:

    Java Code:
    @Action
        public void newBankcheck() {
            System.out.println(bankcheckList.size());
            System.out.println(bankcheckTable.getRowCount());
            cam.entities.Bankcheck bc = new cam.entities.Bankcheck();
            bc.setCompleted(false);
            bc.setPaymentDate(new java.util.Date());
            entityManager.persist(bc);
            bankcheckList.add(bc);
            int row = bankcheckTable.getRowCount()-1;
            bankcheckTable.setRowSelectionInterval(row, row);
            bankcheckTable.scrollRectToVisible(bankcheckTable.getCellRect(row, 0, true));
            setSaveNeeded(true);
            JFrame mainFrame = CAMApp.getApplication().getMainFrame();
            BankcheckEditor bce = new BankcheckEditor(mainFrame, false);
            bce.setCurrentBankcheckRecord(bc);
            bce.setLocationRelativeTo(mainFrame);
            System.out.println(bankcheckList.size());
            System.out.println(bankcheckTable.getRowCount());
            bce.setVisible(true);
            if (bce.isBankcheckConfirmed()) {
                save().run();
            } else {
                refresh().run();
            }
        }
    and here is the error code (notice I have 3 records on the table and want to add the 4th):

    Java Code:
    java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
            at java.util.ArrayList.RangeCheck(ArrayList.java:547)
            at java.util.ArrayList.get(ArrayList.java:322)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:2686)
            at javax.swing.JTable.prepareRenderer(JTable.java:5703)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
            at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
            at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1770)
            at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
            at javax.swing.JComponent.paintComponent(JComponent.java:752)
            at javax.swing.JComponent.paint(JComponent.java:1029)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JViewport.paint(JViewport.java:747)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paint(JComponent.java:1038)
            at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
            at javax.swing.JComponent.paintChildren(JComponent.java:862)
            at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131)
            at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
            at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
            at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
            at javax.swing.JComponent.paint(JComponent.java:1015)
            at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
            at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
            at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
            at java.awt.Container.paint(Container.java:1780)
            at java.awt.Window.paint(Window.java:3375)
            at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
            at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
            at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
            at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
            at java.awt.Dialog$1.run(Dialog.java:1046)
            at java.awt.Dialog$3.run(Dialog.java:1098)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.awt.Dialog.show(Dialog.java:1096)
            at java.awt.Component.show(Component.java:1563)
            at java.awt.Component.setVisible(Component.java:1515)
            at java.awt.Window.setVisible(Window.java:842)
            at java.awt.Dialog.setVisible(Dialog.java:986)
            at cam.CAMView.newBankcheck(CAMView.java:1317)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
            at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
            at java.awt.Component.processMouseEvent(Component.java:6267)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6032)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Any ideas on what might be wrong?
    Thanks in advance
    GK

  2. #2
    madcloud is offline Member
    Join Date
    Dec 2010
    Posts
    9
    Rep Power
    0

    Default

    I m still stack with this, any thoughts anyone?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The line causing the error is where you call setVisible(true) on the dialog? That's unusual. We may need to see an SSCCE to be able to better help you, if this is possible to create (without database code).

  4. #4
    madcloud is offline Member
    Join Date
    Dec 2010
    Posts
    9
    Rep Power
    0

    Default

    Hmmm I dont think I can provide a SSCCE because its very complicated and I m not sure how and if it will through the same exception without the database but I can provide with some screenshots (attached)

    If you notice on the customer table when hitting the new button it opens the customerEditor jDialog and on the background where the customerTable is visible you can see that it creates an empty record selected with blue. Doing the same thing on the bank check table, it does not display this blue line.

    If I remove all the components from the jDialog it still throughs the same exception.

    If I do not add the record on the list
    Java Code:
    bankchecklist.add(bc)
    where bc the persistent bankcheck object, it does not through the error.

    If I dont setVisible the jDialog it does not through the error.

    I m also attaching the customer table code as well as the bankcheck table code that might help although its mostly autogenerated from netbeans.
    customerTable
    Java Code:
    private javax.swing.JTable customerTable;
    
    customerTable.setAutoCreateRowSorter(true);
            customerTable.setName("customerTable"); // NOI18N
            customerTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    
            org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customerList, customerTable);
            org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custSurname}"));
            columnBinding.setColumnName("Cust Surname");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custName}"));
            columnBinding.setColumnName("Cust Name");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custTel}"));
            columnBinding.setColumnName("Cust Tel");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${custAddr}"));
            columnBinding.setColumnName("Cust Addr");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${comments}"));
            columnBinding.setColumnName("Comments");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${totalCost}"));
            columnBinding.setColumnName("Total Cost");
            columnBinding.setColumnClass(Integer.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${totalPayments}"));
            columnBinding.setColumnName("Total Payments");
            columnBinding.setColumnClass(Integer.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${totalUnpaidChecks}"));
            columnBinding.setColumnName("Total Unpaid Checks");
            columnBinding.setColumnClass(Integer.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${total}"));
            columnBinding.setColumnName("Total");
            columnBinding.setColumnClass(Integer.class);
            columnBinding.setEditable(false);
            bindingGroup.addBinding(jTableBinding);
            jTableBinding.bind();
            customerScrollPane.setViewportView(customerTable);
            customerTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("customerTable.columnModel.title0")); // NOI18N
            customerTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("customerTable.columnModel.title1")); // NOI18N
            customerTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("customerTable.columnModel.title2")); // NOI18N
            customerTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("customerTable.columnModel.title3")); // NOI18N
            customerTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("customerTable.columnModel.title4")); // NOI18N
            customerTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("customerTable.columnModel.title5")); // NOI18N
            customerTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("customerTable.columnModel.title6")); // NOI18N
            customerTable.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("customerTable.columnModel.title8")); // NOI18N
            customerTable.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("customerTable.columnModel.title7")); // NOI18N
    
    customerTable.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        //firePropertyChange("recordSelected", !isCustomerSelected(), isCustomerSelected());
                        firePropertyChange("customerSelected", !isCustomerSelected(), isCustomerSelected());
                    }
                });
    
    public boolean isCustomerSelected() {
            return customerTable.getSelectedRow() != -1;
        }
    and for the bankcheckTable:

    Java Code:
    private javax.swing.JTable bankcheckTable;
    
    bankcheckTable.setAutoCreateRowSorter(true);
            bankcheckTable.setName("bankcheckTable"); // NOI18N
            bankcheckTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    
            jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, bankcheckList, bankcheckTable);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${payableTo}"));
            columnBinding.setColumnName("Payable To");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${paymentDate}"));
            columnBinding.setColumnName("Payment Date");
            columnBinding.setColumnClass(java.util.Date.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${checkCode}"));
            columnBinding.setColumnName("Check Code");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${carrier}"));
            columnBinding.setColumnName("Carrier");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${amount}"));
            columnBinding.setColumnName("Amount");
            columnBinding.setColumnClass(Integer.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${completed}"));
            columnBinding.setColumnName("Completed");
            columnBinding.setColumnClass(Boolean.class);
            columnBinding.setEditable(false);
            columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${account.accName}"));
            columnBinding.setColumnName("Account.acc Name");
            columnBinding.setColumnClass(String.class);
            columnBinding.setEditable(false);
            jTableBinding.setSourceUnreadableValue(java.util.Collections.emptyList());
            bindingGroup.addBinding(jTableBinding);
            jTableBinding.bind();
            bankcheckScrollPane.setViewportView(bankcheckTable);
            bankcheckTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title0")); // NOI18N
            bankcheckTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title1")); // NOI18N
            bankcheckTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title2")); // NOI18N
            bankcheckTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title3")); // NOI18N
            bankcheckTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title5")); // NOI18N
            bankcheckTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title4")); // NOI18N
            bankcheckTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("bankcheckTable.columnModel.title6")); // NOI18N
    
    bankcheckTable.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        firePropertyChange("bankcheckSelected", !isBankcheckSelected(), isBankcheckSelected());
                    }
                });
    
    public boolean isBankcheckSelected() {
            return bankcheckTable.getSelectedRow() != -1;
        }
    I hope this will be more clear of whats the problem.
    Thank you again.
    GK
    Attached Thumbnails Attached Thumbnails IndexOutOfBoundsException when jDialog.setVisible(true)-customer-table.jpg   IndexOutOfBoundsException when jDialog.setVisible(true)-bankcheck-table.jpg  

  5. #5
    madcloud is offline Member
    Join Date
    Dec 2010
    Posts
    9
    Rep Power
    0

    Default

    The problem was that the list that was getting the records from the database and was connected with the jtable had to be set as observable in order for this to work.

Similar Threads

  1. Replies: 3
    Last Post: 09-27-2010, 08:07 AM
  2. IndexOutOfBoundsException
    By Luciform in forum New To Java
    Replies: 8
    Last Post: 05-24-2010, 04:44 AM
  3. IndexOutOfBoundsException with AWT-EventQueue-0
    By xcallmejudasx in forum New To Java
    Replies: 0
    Last Post: 03-10-2009, 02:52 PM
  4. IndexOutOfBoundsException
    By aldo1987 in forum New To Java
    Replies: 6
    Last Post: 04-30-2008, 04:48 AM
  5. setVisible(true) does not work
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 2
    Last Post: 10-27-2007, 08:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •