Para conseguir que funcione bien en Griffon lo primero es entender correctamente como funciona en Java, así que tal vez debas echar un ojo a este enlace:
http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html
Aunque siendo realista, es posible que no te apetezca leer tanto así que te pongo un ejemplo básico y listo, :D.
En este ejemplo vamos a ver como se hace el binding de valores de un formattedTextField:
Model:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testformatted | |
import groovy.beans.Bindable | |
class TestformattedModel { | |
@Bindable String mylabel | |
@Bindable Double mynumber | |
} |
View:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testformatted | |
import java.text.NumberFormat | |
import javax.swing.JFormattedTextField | |
application(title: 'testformatted', | |
preferredSize: [320, 240], | |
pack: true, | |
//location: [50,50], | |
locationByPlatform: true, | |
iconImage: imageIcon('/griffon-icon-48x48.png').image, | |
iconImages: [imageIcon('/griffon-icon-48x48.png').image, | |
imageIcon('/griffon-icon-32x32.png').image, | |
imageIcon('/griffon-icon-16x16.png').image]) { | |
// add content here | |
vbox{ | |
label(text:bind{model.mylabel}) | |
textField(text:bind(target: model, targetProperty: 'mylabel')) | |
separator() | |
label(text:bind{model.mynumber}) | |
widget(new JFormattedTextField(NumberFormat.getNumberInstance()),id:"myformatted",value:bind(target: model, targetProperty: 'mynumber')) | |
} | |
} |
A partir de ahi cualquier necesidad diferente pasará casi siempre por jugar con el NumberFormat para crear la máscara adecuada y demás historias.
Ale, que la fuerza te acompañe!
No hay comentarios:
Publicar un comentario