|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Binding JFormattedTextField to JTable in Java Desktop Database Application templateHi All,
I created a Desktop Database application using NetBeans 6.5, very much similar the tutorials on NB, http://www.netbeans.org/kb/docs/java/gui-db.html and http://www.netbeans.org/kb/docs/java/gui-db-custom.html. My Desktop Database app allows user to enter the Price of a product with comma, something like this: 1,000,000.125. I tried to replace Price JTextField with JFormattedTextField but I got error "Exception in thread AWT-EventQueue-0 java.lang.ClassCastException" when enter 1,000.50. I think the comma caused the problem but I don't know how to fix it. This's what I did: - Create Java Desktop Database App by following "Building a Java Desktop Database Application" tutorial. - Add JFormattedTextField to the form; priceFormattedTextField. - Right click on JFormattedTextField > Bind > value > Binding tab: Binding Source: masterTable Binding Expression: ${selectedElement.price} - In the Properties windows, click on "Code" button. - Click on [...] button of "Custom-Creation Code" property. - Enter the following code and press OK: new javax.swing.JFormattedTextField(priceFormatter); - Click on [...] button of "Pre-Creation Code" property, and enter: DefaultFormatter priceFormatter = new NumberFormatter( new DecimalFormat("#,###.000") ); I've spent two days to search for the answers of this problem but haven't found one. My question is how to formatting decimal Price or Total TextFields, which generated by NetBeans Desktop Database App template? So that user can enter something like 1,000,000.150. Please help. Thank you very much in advance. --------------------------------------------------------------------------- Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException at java.lang.Class.cast(Class.java:2990) at org.jdesktop.beansbinding.Binding.convertReverse(Binding.java:1321) at org.jdesktop.beansbinding.Binding.getTargetValueForSource(Binding.java:909) at org.jdesktop.beansbinding.Binding.saveUnmanaged(Binding.java:1268) at org.jdesktop.beansbinding.Binding.save(Binding.java:1254) at org.jdesktop.beansbinding.AutoBinding.trySaveThenRefresh(AutoBinding.java:176) at org.jdesktop.beansbinding.AutoBinding.targetChangedImpl(AutoBinding.java:249) at org.jdesktop.beansbinding.Binding.targetChanged(Binding.java:1433) at org.jdesktop.beansbinding.Binding.access$1300(Binding.java:38) at org.jdesktop.beansbinding.Binding$PSL.propertyStateChanged(Binding.java:1620) at org.jdesktop.beansbinding.PropertyHelper.firePropertyStateChange(PropertyHelper.java:212) at org.jdesktop.beansbinding.BeanProperty.notifyListeners(BeanProperty.java:712) at org.jdesktop.beansbinding.BeanProperty.access$1000(BeanProperty.java:143) at org.jdesktop.beansbinding.BeanProperty$SourceEntry.cachedValueChanged(BeanProperty.java:369) at org.jdesktop.beansbinding.BeanProperty$SourceEntry.propertyValueChanged(BeanProperty.java:409) at org.jdesktop.beansbinding.BeanProperty$SourceEntry.propertyChange(BeanProperty.java:414) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276) at java.awt.Component.firePropertyChange(Component.java:7961) at javax.swing.JFormattedTextField.setValue(JFormattedTextField.java:782) at javax.swing.JFormattedTextField.commitEdit(JFormattedTextField.java:513) at javax.swing.JFormattedTextField$FocusLostHandler.run(JFormattedTextField.java:632) at javax.swing.JFormattedTextField.processFocusEvent(JFormattedTextField.java:614) |
|
|
Re: Binding JFormattedTextField to JTable in Java Desktop Database Application templateI don't remeber how i get this solution but it's working for me. I'm using netbeans 6.5 but the solution was implemented since netbeans 5.x
1. Unbind your jformattedtextfield from jtable 2. Right click to your jformattedtextfield and select porperties 3. Select "Binding" tab next to "Properties" 4. Look for "text" in the list and click in [...] 5. You'll see that now you are binding text property (java.lang.String) instead value property (java.lang.Object) 6. Select your Jtable as Binding source 7. Select Binding Expression to be bind to your Jformattedtextfield That's all. I hope this help you. |
| Free embeddable forum powered by Nabble | Forum Help |