aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes A problem adding a row in JTable using a button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A problem adding a row in JTable using a button" Watch "A problem adding a row in JTable using a button" New topic
Author

A problem adding a row in JTable using a button

hany hashemi
Greenhorn

Joined: Dec 17, 2008
Posts: 14
Hi everybody,
I have a Jtable which is filled by the data related to MySql table.I added a button and i want the JTable to add a row while i am pressing the Insert button.
This is a part of my code.



I will be appreciative if somebody can help me solving this problem.
Thanks
Hany
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
hany hashemi wrote:Hi everybody,
I have a Jtable which is filled by the data related to MySql table.I added a button and i want the JTable to add a row while i am pressing the Insert button.
This is a part of my code.



I will be appreciative if somebody can help me solving this problem.


I can't really help you solve "this problem" because you didn't actually say you had a problem. Perhaps you should describe how your code behaves differently from how you expect.

I will mention that you shouldn't have to call fireTableStructureChanged because you are using DefaultTableModel and its methods (such as addRow) fire events automatically.

Are you sure that your addNewRow method is even being called? If you put a println in there do you see any output?


bitguru blog
hany hashemi
Greenhorn

Joined: Dec 17, 2008
Posts: 14
I use the println and i saw that addNewRow method was called.I also comment the line related to fire a table but after pressing the insert button ,instead of adding a new row at the bottom of my table , i faced to these massages:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Where do you initialize your table model?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 89
Hi,

If you can post the complete code then we would be able to pin point to the problem.

We have to know when that action is called? How many columns does your table hold? etc.,

Can you insert the code please.


Karthick D V
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

The complete code is not necessary. We already know from the stack trace that one field in this code is null:

Since item is a newly created Vector that can't be null, and the only other variable that is dereferenced here is model. So that tells me that model == null, probably because it was only declared and never initialized.
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 89
Hope that in the stack trace we will get "caused by".

By the line number in the trace if we can get hold of the line number that caused nullpointerexception. From the line we can see what is null.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A problem adding a row in JTable using a button