Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding row to a JTable

843805Jul 14 2006 — edited Jul 17 2006
I've created a JTable which uses AbstractTableModel because i need to display booleans as check boxes. It is inside a JScrollPane and the table loads fine with the data I add to the data vector before the table is displayed, but I'm not able to add a row later or even modify existing data. I've tried all the fireTable* methods I found in the API, but nothing worked. The vector is updated with the new data, but it is not displayed in the table. The only way I am able to modify the JTable during runtime is when I change values in the event handler like this:
public void actionPerformed(ActionEvent e)
{
	Object source = e.getSource();
	if ("execute".equals(e.getActionCommand()))
		table.setValueAt("data",1,1);
}
Unfortunately this only works when a button is pressed, but JTable needs to display a list of clients which updates as they connect.
This is the addRow method i tried to use that does not work:
public void addRow(String name, String response, Boolean active)
{
	int size = data.size();
	data.addElement(new cpu(name, response, active));
	fireTableRowsInserted(size, size);
}	
I've been struggling with this for a few days now,so ANY suggestions will help.
Thank you very much!!!

P.S. here's what I've tried and it didn't work:
table.addNotify();
fireTable*(everything)
repaint();

I'm out of ideas.

Message was edited by:
daqqad
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 14 2006
Added on Jul 14 2006
23 comments
1,130 views