• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting the position of cell

 
lavanya subramanian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
i have a JFrame which has a toolbar and 2 JInternalFrames(each of which contains 1 JTable).
when i select a cell in any of the JTables and click a button in the tool bar,i should get the value of the cell.
could anybody help me in this issue,
thanks in advance
lavanya
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
If you are only going to have two tables you could ask each table to supply it's selected cell value:

To do this the tables must be visible outside the JInternalFrames
If you want a more flexible model then try adding a MouseAdapter to the tables passing a reference to the owner JInternalFrame in the MouseAdapter constructor and have the mousePressed event pass that reference back to a setSelectedInternalFrame() method which changes a variable in your program so the last JInternalFrame operated on is always known.
Extend the JInternalFrame class and when adding the table create a variable "table" and give it a reference to the table. Include a getTable() method that returns a JTable.
Then the code to get the value would change:

Now it doesn't matter how many InternalFrames you have in the future.
P.S.: You might want to consider returning a copy of the table( a new table with the same contents) instead of a reference if you want to protect the integrety of the original table and it's data.
Hope that helps,
 
lavanya subramanian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Terry,
thanks,it's working
lavanya
 
lavanya subramanian
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Terence,
sorry for my misspell your name in my previous mail.
it's working but
when i make a selection in the table in the first frame the second frame is instantiated and works fine.
but when i make another selection in the table in the first frame the second frame is instantiated and displays fine.but when i click the second frame the previous selection retains there,so what should i doto get the value updated.
help is appreciated,
lavanya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!