spng
|
Posted: November 08, 2009 10:44 by spng
|
|
There is a button that must print the value of JTextField when pressed. map :view => "JTextField1.text", :model => :field The value of field never changes even though the text of JTextField is changed by the user. Is this possible in MonkeyBars? Example code is appreciated. |
JTextField text on action performed?
by: Logan Barnett
Logan Barnett
|
Posted: November 11, 2009 04:30 by Logan Barnett
|
|
You need a document listener, not an action listener. The action listener works when you press enter or make the text field lose focus. Here's what we use in one of our apps any time the text changes at all (not just keystrokes, but drag/drop of text and copy/paste):
Be aware that if you do an update_view in one of these events that you can cause an infinite loop (the update_view changes your text field, which fires the event again, which calls update_view again... etc). You can work around this with :ignoring in the view. See View.map for details: http://monkeybars.rubyforge.org/api/classes/Monkeybars/View.html#M000091 Another option if you are in a raw_mapping is to use disable_handlers: http://monkeybars.rubyforge.org/api/classes/HandlerContainer.html#M000157 If you find this helpful can you add some recipes to the wiki? Thanks in advance! |
spng
|
Posted: November 11, 2009 06:51 by spng
|
|
def button_action_performed puts license_key_text end The nice code posted does not print the value of JTextField when button is pressed. insert_update gives Java::JavaxSwingText::AbstractDocument: efaultDocumentEvent. If JTextField is 123, when button is pressed 123 must be printed. Java solution is license_key_text.getText()
|
Logan Barnett
|
Posted: November 12, 2009 13:42 by Logan Barnett
|
|
I misunderstood what you were trying to do. Given you still have the original mapping, this is what you would do:
|
Logan Barnett
|
Posted: November 18, 2009 15:27 by Logan Barnett
|
|
You have to make yourself a member of the project, which is done on the left blue panel, near the bottom if I remember correctly. Then you can edit the wiki all you like! |
by: Logan Barnett


efaultDocumentEvent. If JTextField is 123, when button is pressed 123 must be printed. Java solution is license_key_text.getText()





