wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Problems with Jtable and JTextField Binding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems with Jtable and JTextField Binding" Watch "Problems with Jtable and JTextField Binding" New topic
Author

Problems with Jtable and JTextField Binding

vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
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!


SCJP 5.0<br />SCWCD1.4<br />SCBCD5
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10403
    
    8

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?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
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

Joined: Jul 26, 2007
Posts: 10403
    
    8

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

Joined: Sep 07, 2007
Posts: 100
Thanks Maneesh,that works
vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
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

Joined: Jul 26, 2007
Posts: 10403
    
    8

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Problems with Jtable and JTextField Binding