Solved

problem with editing in a Jtable

Posted on 2004-03-23
8
341 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
Comment Utility
Add a TableModelListener to your table's model that enables your form whenever a cell is changed.
0
 
LVL 92

Expert Comment

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

Author Comment

by:guidway
Comment Utility
will try it in a few minutes... thanks
0
 
LVL 12

Author Comment

by:guidway
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 92

Accepted Solution

by:
objects earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to use external config file with Spring MVC 4 59
Fibonacci challenge 11 81
wordmultiple challenge 12 89
maven project error 5 17
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now