JTextField text on action performed?

  6 posts   Feedicon  
Replies: 5 - Last Post: November 18, 2009 15:27
by: Logan Barnett
showing 1 - 6 of 6
 
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.
 
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):

 # In the controller
add_listener :type => :document, :components => {"license_key_text.document" => "license_key_text"}

def license_key_text_insert_update
    ...
end

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!

 
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:GrinefaultDocumentEvent. If JTextField is 123, when button is pressed 123 must be printed. Java solution is license_key_text.getText()
 
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:

def button_action_performed
  update_model(view_model, :field)
  puts model.field
end
 
Posted: November 18, 2009 09:53 by spng
error message You are not allowed to do that (write wiki)
 
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!

showing 1 - 6 of 6
Replies: 5 - Last Post: November 18, 2009 15:27
by: Logan Barnett
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close