• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problems with Jtable and JTextField Binding

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maneesh,that works
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic