aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes update textArea when row is selected 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 "update textArea when row is selected" Watch "update textArea when row is selected" New topic
Author

update textArea when row is selected

jordan ryan
Greenhorn

Joined: Oct 31, 2012
Posts: 23
this is just the gui, practically im creating a table that reads emails from an account, then it displays the from, subject and date. when i click on the row i want it to show that rows message but at the moment im just trying to get it to say "action clicked". any help would be great.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

You need to listen to table selection events and then update the JTextArea accordingly
Recommended reading: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#selection


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
jordan ryan
Greenhorn

Joined: Oct 31, 2012
Posts: 23
sorry that has confused me a bit, So where am i going wrong as i had this sort of code working on a different application :/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

You aren't really going wrong as such, you just don't have any code yet which identifies when a row is selected. I was going to post a link to the JTable tutorial, but I just noticed that Maneesh already posted the exact link I was going to post.

The tutorial comes with sample code. The code associated with Maneesh's link shows you how to add the appropriate listener for table row selections, and then it's up to you to have that listener update your text field. That wouldn't be much different than what the sample code does, really.
jordan ryan
Greenhorn

Joined: Oct 31, 2012
Posts: 23
oww the reason im confused is because if i do an actionListener on a button with that rowSelected code i already have, then it seems to work.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1085
    
  10

yah, it will if you have the same code in the actionListener of the button.

If you want the update to happen when the user clicks the button, then, you need to add an action listener for the button.
If you want the update to happen when the user clicks on the table (to select a row), then you need to add an selection listener for the table.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
jordan ryan
Greenhorn

Joined: Oct 31, 2012
Posts: 23
yer sorry it was silly of me i just added a mouseclicker, For some reason i was thinking it would just work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: update textArea when row is selected