Solved

JTable

Posted on 2007-03-25
3
386 Views
Last Modified: 2013-12-14
I am currently developing an application which uses a swing JTable and have no time to properly read the documentation.

Users are able to edit cells in the JTable, and I need to know how to create a Listener that simply provides me with the following:

* the String value that the user has typed into this cell
* the int value that represents the row of this cell
* the int value that represents the column of this cell
0
Comment
Question by:momonja
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 125 total points
ID: 18789797
0
 

Author Comment

by:momonja
ID: 18790020
Thank you for your help.
So far, I have managed to write the following code:

public class MyTableModelListener implements TableModelListener {
        JTable table;
        public MyTableModelListener(JTable table) {
            this.table = table;
        }
        public void tableChanged(TableModelEvent e) {
            int firstRow = e.getFirstRow();
            int lastRow = e.getLastRow();
            int mColIndex = e.getColumn();
            switch (e.getType()) {
                case TableModelEvent.UPDATE:
                    for (int r=firstRow; r<=lastRow; r++) {
                        // (r, mColIndex)
                        // do whatever it has to do
                    }
                    break;
            }
        }
    }

Where I've written "// do whatever it has to do" I need to get the Object that is in that cell (In this case, a String), how do I do that?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18790118
Use getValueAt () ;

String value = ( String ) table.getValueAt ( r, mColIndex ) ;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java array passed to SQL where clause 23 64
Java - Why doesn't this JFrame work 3 44
how do i compare an object based on two fields 6 49
jar file executable 12 43
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

867 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

22 Experts available now in Live!

Get 1:1 Help Now