Solved

How to get the object bound  to the currently selected row of a JTable ?

Posted on 2008-06-16
2
552 Views
Last Modified: 2013-12-14
Hello,

I'm working on a J2SE desktop application (client/server) where I'm using beans binding to display the result of a query in a JTable.
How do I gain access to the bound object that corresponds to the currently selected row of the JTable?
I'm a new JAVA programmer and I'm using Java 5.0 + Netbeans IDE 6.1.
0
Comment
Question by:optima-sc
2 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21798490
0
 

Accepted Solution

by:
optima-sc earned 0 total points
ID: 21801859
Well, I guess I did not formulate my question correctly:
I have a list of business objects displayed in JTable via beans binding (so that the list and the jTable are kept in sync at all times). I need to get a reference to the underlying business object (in the business object list) corresponding to the row selected in the JTable.
I had already figured that the Table property would be getSelectedRow, but I needed to be able to link that row to the source business object.
It turns out that the solution is quite simple in fact:
     int index = displayTable.getSelectedRow();
     mydesktopapplication.BusinessObject o = sourceList.get(index);
Thank you for your time, anyway!
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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

832 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