Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enable to get jTable value(s) on click of jbutton outside the table

 
Praveen Chadichal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anyone help me on how to get the jtable cell value(s) on click of a button. The button is outside the jtable. Once i enter the value in the cell & click on the button the value should be available. I tried too much on this but the value is everytime empty. Quick response is deeply appreciated. Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you retrieve the table's cell value(s)? Also, do you click on the button while the table cell is still in edit mode? If so, you may want to try the following when you create your table:
This will make sure that just as soon as the table loses its focus (e.g. because of a button click), it stops the editting and commits its value to the table model.
 
Praveen Chadichal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
Thanks for your reply, i tried the same what you said, following is the image for how the page looks: {If image is not visible pelase refer the attachment}
So when i enter the in the 3rd column of the table and click on the DONE button the value in this cell should be printed(for now). But still the value is coming empty.
Following is the code for the button action:
private void DoneButtonActionPerformed(java.awt.event.ActionEvent evt) {
PaymentsTable.putClientProperty("terminateEditOnFocusLost", false);
System.out.println("=====>"+PaymentsTable.getModel().getValueAt(0, 2));
}

Can you please help me on this?
paymentTab.JPG
[Thumbnail for paymentTab.JPG]
Table & button image view
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pavi Praveen wrote:PaymentsTable.putClientProperty("terminateEditOnFocusLost", false);

You should call that long before the button click, right after you've created the table.

Alternatively, you can use the following:
 
Praveen Chadichal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
I dint get you exactly? what did you meant by "You should call that long before the button click, right after you've created the table. ".
You have ask to call it before button click, actually where did you refer? the code that you gave , where should it be called?
The table will be created as the page loads & on entering a value in the cell i directly hit the DONE button and so the value must be populated, but thats not happening.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I said "when you create your table". So something like But if that fails, the other code I gave you yesterday should work as well, provided that the editor allows stopping. (If the value does not match the editor's expected value, e.g. numeric, it can return false and not stop.)
 
Praveen Chadichal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow Rob excellent, thanks it worked.. Thanks a millions!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic