aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes getting value from JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting value from JTable" Watch "getting value from JTable" New topic
Author

getting value from JTable

Ruel Soriano
Greenhorn

Joined: May 17, 2007
Posts: 12
greetings,
how can i get value from JTable and set it to textfield. I have to classes, one for JTable class and other for Textfield class, how can i get the value when i select value from JTable class and put it on textfield which is another class.....
i really need this, please help me.....
thanks..
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"rule_S" -

Welcome to the JavaRanch! We don't have many rules around the ranch, but we do have a policy on displayed names... Please adjust your displayed name to meet the JavaRanch Naming Policy. User names cannot be obviously fake and must consist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You'll have to use a Listener to listen for events in the table, and in response to those events, set the text of the textfield.

Ruel Soriano
Greenhorn

Joined: May 17, 2007
Posts: 12
Thanks for the reply.....but I have something to add, I want my selected value from the table will be display to another class. For example, class Table and Class Main....when i click button Find in the Main class the table from Table Class will be display and when I select value from the table and click the button Select the selected value will display to the Textfield of Main Class. How can i get it.
Many thanks and I hope you could help me again.......
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Create/handle the listener in the Main class, add it to the Table class.
Ruel Soriano
Greenhorn

Joined: May 17, 2007
Posts: 12
thanks for the reply, but could you please give me a brief example of that code, i really don't know how to do that.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

There are *lots* of ways to do that - and a lot of it depends on how those two classes are currently implemented - here's one way to do it...

TableSelection class - aka "Main"


TableSelectionPanel class - aka "Table"
Ruel Soriano
Greenhorn

Joined: May 17, 2007
Posts: 12
Thanks for the code, it really helped me, your a saver.....
till next time.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting value from JTable