Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update textArea when row is selected

 
jordan ryan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jordan ryan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jordan ryan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yer sorry it was silly of me i just added a mouseclicker, For some reason i was thinking it would just work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic