Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with Jtable and JTextField Binding

 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Ranches

I have implemented a JTable in JScrollPane,Jtable's data comes from MyAbstractTableModel, which has a JDBC ResultSet,in JTable,data is displayed,and I can changed them,and save then back to database.
problem is that I add a JTextField in bottom of my JDialog,which is the container of JScrollPane,I want this JTextField binding with a JTable's field,in other words,I need bind the JTextField to one column of JDBC ResultSet,how to do that? or can I do that


any advice would be appreciated!

 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you mean by binding the text field to the column? Can you please elaborate a bit more on what you are trying to do here?
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.

What I am doing here is that I don't want data to be edited in JTable cell,I want data to be edited in a JTextField in the bottom of form,because I have lots columns in JTable,so when user click a row in JTable,The JTextField which connect with a column should display that record's column's value,and let user to change the value?then change the resultSet in TableModel,later changes will submit to database.
thanks
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you need is a selection listener. You need to find out which row/column was selected by the user, pick out the values (getValueAt()) and display them in the text field(s).
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh,that works
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can update The JTextFields now,I have another problems now,How can I tell myAbstratcTableModel that data has been updated,then we need update ResultSet ,then JTable
which event litener should i implemented?
Thanks advance
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I imagine, the user types in the edited value in the text field and hits enter or clicks on a save button or something to commit the edit. In that case you can have an action listener (which you can share between the button and text field). In the action performed, you will need to take the edited value and pass it on to the model. In the model's setValueAt() or whatever method you use, you will need to make the db call. Just make sure, that in case the db call fails, you do not update your model value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic