Solved

JTable

Posted on 2007-03-25
3
384 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:
mayankeagle 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:mayankeagle
ID: 18790118
Use getValueAt () ;

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 70
strCopies  challenge 17 73
backtracking recursion  code 19 40
starter POM and spring-boot-starter,  spring-boot-web 2 11
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

707 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

13 Experts available now in Live!

Get 1:1 Help Now