problem with editing in a Jtable

I have created a JTable that allows a user to edit a row inside of it. I set it up so that it will display comboboxes/etc... inside of it and that all works fine. Now here is the part that is tricking me up. When the user finished editing a row I want a button on the form to become enabled so that the user can click that button to update changes on the table permanently. I can't see how to know when the table is edited to make that button enabled. any ideas? thanks

guid
LVL 12
guidwayAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
The model should be firing that event.
Did you add the listener to you model? model.addTableModelListener(mylistener);
0
 
objectsCommented:
Add a TableModelListener to your table's model that enables your form whenever a cell is changed.
0
 
objectsCommented:
public void tableChanged(TableModelEvent e)
{
   if (e.getType()==TableModelEvent.UPDATE)
   {
      // enable button if appropriate
   }
}
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
guidwayAuthor Commented:
will try it in a few minutes... thanks
0
 
guidwayAuthor Commented:
hi objects,

I added the code and placed my code to make the button enabled however nothing happens. It appears the event is not getting fired. Does this event need to be subclassed or something?
0
 
kiwi_alienCommented:
Even if you don't use a model specifically just grab your model with

TableModel myModel = myTable.getDefaultTableModel()

and add your listener with

myModel.addTableModelListener(new MyTableListener());  // like objects said

with MyTableListener being something like:

public class MyTableListener extends DefaultTableListener
{
  // Same code as objects
  public void tableChanged(TableModelEvent e)
  {
     if (e.getType()==TableModelEvent.UPDATE)
     {
        // enable button if everything in table is updated to your satisfaction
     }
  }
}
0
 
guidwayAuthor Commented:
heh heh, one of these days I'm going to learn that an event has to be fired by an object before it runs... <embarrassed and crawls up under the nearest rock>. thanks objects. :)
0
 
objectsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.