Solved

problem with editing in a Jtable

Posted on 2004-03-23
8
345 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

685 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