Solved

JTable

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 84
Java - Why doesn't this JFrame work 3 59
Java Options in Zimbra Server 2 52
maven module vs maven project 3 23
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 functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

770 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