aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Enable to get jTable value(s) on click of jbutton outside the table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Enable to get jTable value(s) on click of jbutton outside the table" Watch "Enable to get jTable value(s) on click of jbutton outside the table" New topic
Author

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

Praveen Chadichal
Greenhorn

Joined: Apr 07, 2009
Posts: 21
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Praveen Chadichal
Greenhorn

Joined: Apr 07, 2009
Posts: 21
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?



[Thumbnail for paymentTab.JPG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

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

Joined: Apr 07, 2009
Posts: 21
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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

Joined: Apr 07, 2009
Posts: 21
Wow Rob excellent, thanks it worked.. Thanks a millions!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enable to get jTable value(s) on click of jbutton outside the table