[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JTable

Posted on 2007-03-25
3
Medium Priority
?
404 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
[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
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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:
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.
Suggested Courses

649 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