• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with displaying data in a JTable

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)




 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not getting an idea how to do it so please help me
 
prajna pa
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've already told you that.

clean your glasses.
 
prajna pa
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that has nothing to do with fixing your problem.

it is simply an improvement on your design.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic