Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with displaying data in a JTable

 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Java program:
I am finding little difficulty in my program.Here i am editing the table data through textfield and while returning back to the table it is not updating showing error.i will copy my program






//*******************************
i am getting the error as
*****************************

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 3
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:648)
at formlayout.DisplayTableAction.setTextData(DisplayTableAction.java:203)
at formlayout.TablePanel.actionPerformed(TablePanel.java:214)
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.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)




 
fred rosenberger
lowercase baba
Bartender
Posts: 12087
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, do you REALLY expect someone here to give up their free time and go through 450 lines of unformatted code? I have copied your java and put it inside code tags, which is really the minimum expected.

Next, the error tells you exatly what the problem is. You are trying to access the 6th element of an array that doesn't have six elements. The fix is to not do that.

 
Campbell Ritchie
Sheriff
Posts: 48441
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote: . . . I have copied your java and put it inside code tags, . . .
I added code tags too, and got rid of some of the long lines. It would have looked a lot better had you not mixed tabs and spaces for your indenting.
 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not getting an idea how to do it so please help me
 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to fred rosenberger

thank you for putting the code in tags.

here in my table i am adding the rows after that i am editing and updating so its showing an error. so please can you help me...
Thanks in advance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> here in my table i am adding the rows after that i am editing and updating

no, you're not

this is what you're actually doing:
creating/showing a table with 3 rows
editing a row:
disposes the frame/table
opens another frame with editing fields
when OK, creates/shows a new frame/table (not the original one)

so, if you add some rows, then edit one of those rows,
the selected row number will be > than the 3 in the newly
created table

in TablePanel's actionPerformed you have this
display=new DisplayTableAction();
...
display.setTextData(s1,s2,s3,s4,row_number);

so, 'display' is not the same frame/table you are trying to edit/update,
it is a 'new' one, with only the default 3 rows.

you just need to pass a reference of DisplayTableAction to TablePanel
and use setVisible(false/true) instead of dispose()

[edit]
actually, you'd be better off not using setVisible(false/true) at all,
instead TablePanel should be a modal JDialog meaning you can still see
the table but cannot access it until the dialog is disposed
 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i had remove the dispose() code
still it is not working.....
i am a begginner to java so please can you explain me clearly


Thank you in advance
 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any one please help me i need to submit it today please...within 4.00
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you'd spent your time following my
instructions you would have solved your
problem by now.

reposting indicates you just want someone
to fix it. if so, pay for it and there's
a site called rent-a-coder you should visit
 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am asking you how to access the table after adding the rows
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've already told you that.

clean your glasses.
 
prajna pa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TablePanel should be a modal JDialog meaning you can still see
the table but cannot access it until the dialog is disposed


i am not getting this
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that has nothing to do with fixing your problem.

it is simply an improvement on your design.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic