Solved

JTable

Posted on 2007-03-25
3
401 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 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

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

Suggested Solutions

Title # Comments Views Activity
Adding multiple JVM environments to RedHat 6 7 70
jsp CRUD operations with and without prepared statement also hibernatge 1 31
glassfish admin console 1 23
Java array 21 87
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

730 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