This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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.
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).
Joined: Sep 07, 2007
Thanks Maneesh,that works
Joined: Sep 07, 2007
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?
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Problems with Jtable and JTextField Binding