This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Need help with displaying data in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help with displaying data in a JTable" Watch "Need help with displaying data in a JTable" New topic
Author

Need help with displaying data in a JTable

prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36

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

Joined: Oct 02, 2003
Posts: 11153
    
  16

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.



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
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

Joined: Oct 04, 2012
Posts: 36
i am not getting an idea how to do it so please help me
prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Oct 04, 2012
Posts: 36
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

Joined: Oct 04, 2012
Posts: 36
any one please help me i need to submit it today please...within 4.00
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 04, 2012
Posts: 36
i am asking you how to access the table after adding the rows
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I've already told you that.

clean your glasses.
prajna pa
Ranch Hand

Joined: Oct 04, 2012
Posts: 36
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

Joined: Jun 09, 2003
Posts: 4632
that has nothing to do with fixing your problem.

it is simply an improvement on your design.
 
wood burning stoves
 
subject: Need help with displaying data in a JTable
 
Similar Threads
Trouble executing(actionlistener) the swing applet properly in html
Clip Board Problem
Clip Board Problem
Problem with java layout and panels and containers
jmenubar,menuitem