Passing JPanel to JOptionPane and returning a text entry
843806Apr 15 2008 — edited Apr 15 2008Hi all
I created a QWERTY virtual keyboard in a JPanel for entering text. In my program,
when a person wants to enter a name in a text field in a panel, I pop up a JOptionPane
.showmessagedialog window and pass the QWERTY panel as the message. Fine
so far... When typing in text in the text field of this QWERTY panel, I want the text
entry to be reflected in the text field of the parent panel. When I click 'OK' to close
the option pane, the text entered from the QWERTY panel is not reflected in the parent
panel text field.
I tried a couple of things - when I instantiated the QWERTY panel prior to passing
to the j option pane, I passed the parent jtextfield in the constructor and reference that
to the QWERTY textfield. No luck
I then tried getting the text value (String) in the jtext field of the parent and passing to the QWERTY
constructor and referencing the QWERTY string value to the passed String value.
In this case, the String value does pass to the QWERTY panel and I can edit. Now,
when I click OK to close the JOptionPane, Im checking for a component shown event
to update the local jtextfield with the String in the QWERTY panel. BUT, closing the
JOptionPane did not trigger the component shown event.
So, couple of questions - is there a good way to have values in a component changed
in a JOptionPane (as a message) propagate back to the parent? And, when closing the
joptionpane, how do I catch that event in the parent calling pane? Any thoughts?
Thanks
Mike