Consegui rodar com o codigo que vc me passou, porém ao tentar linkar com o meu bean de negocio (classe modelo):
txtVendas = new JTextField();
NumberFormatter numberFormatter = new EmptyNumberFormatter(NumberFormat.getInstance(), new BigDecimal("0"));
numberFormatter.setValueClass(BigDecimal.class);
ValueModel bigDecimalModel = new ValueHolder( presentation.getModel(InformacoesFinanceiras.VENDAS));
bigDecimalModel.addValueChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("mudou para " + ((BigDecimal) evt.getNewValue()).doubleValue());
}
});
txtVendas = BasicComponentFactory.createFormattedTextField(bigDecimalModel, numberFormatter);
Bindings.bind(txtVendas, bigDecimalModel);
Eu pego a seguinte exception:
Exception in thread "AWT-EventQueue-0" com.jgoodies.binding.beans.PropertyAccessException: Failed to set an adapted Java Bean property.
cause=java.lang.IllegalArgumentException: Cannot format given Object as a Number
bean=javax.swing.JFormattedTextField[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY= 0.0,border=com.birosoft.liquid.borders.LiquidTextFieldBorder@1220fd1,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource [r=167,g=165,b=163],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=3,g=3,b=3],selectionColor=javax.swing.plaf.ColorUIResource[r=169,g=209,b=255],columns=0,columnWidth=0,command=,horizontalAlignment=LEADING]
bean type=javax.swing.JFormattedTextField
value=null
value type=com.jgoodies.binding.beans.BeanAdapter$SimplePropertyAdapter
property name=value
property type=java.lang.Object
property setter=public void javax.swing.JFormattedTextField.setValue(java.lang.Object)
Ele me diz que o objeto não pode ser casteado para número, mas o tipo que está na classe é um BigDecima!
O lugar para linkar seria esse?
ValueModel bigDecimalModel = new ValueHolder(presentation.getModel(InformacoesFinanceiras.VENDAS));
Valeu mesmo Hugo.
Vc tá me quebrando um galhão!