Solved

problem with editing in a Jtable

Posted on 2004-03-23
8
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:
Suggested Courses

632 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