Solved

problem with editing in a Jtable

Posted on 2004-03-23
8
344 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:guidway
  • 4
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10663987
Add a TableModelListener to your table's model that enables your form whenever a cell is changed.
0
 
LVL 92

Expert Comment

by:objects
ID: 10663991
public void tableChanged(TableModelEvent e)
{
   if (e.getType()==TableModelEvent.UPDATE)
   {
      // enable button if appropriate
   }
}
0
 
LVL 12

Author Comment

by:guidway
ID: 10664013
will try it in a few minutes... thanks
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
LVL 12

Author Comment

by:guidway
ID: 10664083
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
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 10664104
The model should be firing that event.
Did you add the listener to you model? model.addTableModelListener(mylistener);
0
 
LVL 1

Expert Comment

by:kiwi_alien
ID: 10664128
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
 
LVL 12

Author Comment

by:guidway
ID: 10664151
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
 
LVL 92

Expert Comment

by:objects
ID: 10664193
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 42
Is Applet the way to go for my drag and drop system? 8 25
java example issue 5 25
learn programming 8 42
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question