I am unsure about how I can fill the JTextField
of a frame from a JTable
by double clicking another frame. I would like that when the user double clicks on the record in JTable
and closes the frame, the same data should be put in JTextField
in the frame.
Asked
Active
Viewed 299 times
-1

trashgod
- 203,806
- 29
- 246
- 1,045

galla.info
- 33
- 3
-
2Post some code instead of verbose (and un-understandable) text. – Guillaume Polet Feb 04 '13 at 14:08
-
Could you please be a little more elaborate? An example maybe? So you have a text field that should be filled with the data of a table-row when you double click on that row, right? What I don't get is the part about closing the frame. – Simon Hellinger Feb 04 '13 at 14:12
-
1See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) The 2nd 'frame' should be a modal `JDialog` or a `JOptionPane`. Deal with the user actions the line of code after the dialog is set visible. – Andrew Thompson Feb 04 '13 at 14:16
-
sure, if I was not very clear, my question is this, I've done a query on the database and put a few customer records, such as code, name and city in the JTable. This JTable in a frame B. From the moment that the user you double click on the record of the JTable I want to get the registration code to another query on the bench with this code and put all the data in their fields in the frame JTextField A. Only when the user double-clicking this der want this frame B closes with dispose () and the data has come in JTextField setados corresponding frame B. Any suggestions? – galla.info Feb 04 '13 at 16:56
1 Answers
1
Add your JTable
to a modal JDialog
or JOptionPane
.
For single-click, add a
ListSelectionListener
, as shown here.For double-click, add a
MouseListener
, as shown here.
In either case, you can use the result of getSelectedRow()
. Note: the result is in view coordinates. If you use that result to access your TableModel
, "always remember to translate cell coordinates."
-
sure, if I was not very clear, my question is this, I've done a query on the database and put a few customer records, such as code, name and city in the JTable. This JTable in a frame B. From the moment that the user you double click on the record of the JTable I want to get the registration code to another query on the bench with this code and put all the data in their fields in the frame JTextField A. Only when the user double-clicking this der want this frame B closes with dispose () and the data has come in JTextField setados corresponding frame B. Any suggestions? – galla.info Feb 04 '13 at 16:56
-
Please edit your question to include an [sscce](http://sscce.org/) that shows your current approach based on the suggestions above. – trashgod Feb 04 '13 at 22:01