{"id":89,"date":"2011-07-18T21:35:27","date_gmt":"2011-07-19T03:35:27","guid":{"rendered":"http:\/\/sha.nnoncarey.com\/blog\/?p=89"},"modified":"2012-11-16T18:09:32","modified_gmt":"2012-11-17T00:09:32","slug":"using-jformattedtextfield-with-swing-data-binding-from-tornado-no","status":"publish","type":"post","link":"https:\/\/sha.nnoncarey.com\/blog\/archives\/89","title":{"rendered":"Using JFormattedTextField with Swing Data Binding from tornado.no"},"content":{"rendered":"<p>Although there are many data binding libraries available for Swing, the one I have been dealing with lately is from <a href=\"http:\/\/databinding.tornado.no\/\">http:\/\/databinding.tornado.no\/<\/a><\/p>\n<p>After I added a JFormattedTextField as a bound field, I noticed that it wasn&#8217;t obeying the text-to-value and value-to-text conversion that I had specified in my Formatter. Instead, the data binding was trying to populate the model with the text from the field instead of the value. A look at the source code of CoreUIBridgeProvider shows that JTextFieldBridge is used for JFormattedTextFields, and that bridge only gets &#038; sets the text of the field. Its behavior is sufficient for JTextField, but not for proper use of JFormattedTextField.<\/p>\n<p>To fix the issue, I wrote a custom bridge specifically for formatted fields. It simply passes the value object straight through it.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Override\r\npublic void setUIValue(JFormattedTextField component, Object value) throws ConversionException {\r\n    component.setValue(value);\r\n}\r\n\r\n@Override\r\npublic Object getUIValue(JFormattedTextField component) throws ConversionException {\r\n    return component.getValue();\r\n}\r\n<\/pre>\n<p>After I added a new entry to my bridge provider to map my new bridge to my custom JFormattedTextField class, it immediately started working as expected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although there are many data binding libraries available for Swing, the one I have been dealing with lately is from http:\/\/databinding.tornado.no\/ After I added a JFormattedTextField as a bound field, I noticed that it wasn&#8217;t obeying the text-to-value and value-to-text conversion that I had specified in my Formatter. Instead, the data binding was trying to &hellip; <a href=\"https:\/\/sha.nnoncarey.com\/blog\/archives\/89\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using JFormattedTextField with Swing Data Binding from tornado.no&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":8,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions\/195"}],"wp:attachment":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}