"…
Note that although the JFormattedTextField class inherits the setText method from the JTextField class, you do not usually call the setText method on a formatted text field. If you do, the field’s display changes accordingly but the value is not updated (unless the field’s formatter updates it constantly).
To obtain a formatted text field’s current value, use the getValue method. If necessary, you can ensure that the value reflects the text by calling the commitEdit method before getValue . Because the getValue method returns an Object , you need to cast it to the type used for your field’s value. …"
private JComponent addVector3fProperty(Object bean, String property) {
PropertyAccess<Vector3f> beanPropAccess = new PropertyAccess<>(bean, property);
Vector3f vec = beanPropAccess.getValue();
FloatFormatFactory floatFormatFactory = new FloatFormatFactory(-1000, 1000);
JFormattedTextField xTextField = new JFormattedTextField(floatFormatFactory);
JFormattedTextField yTextField = new JFormattedTextField(floatFormatFactory);
JFormattedTextField zTextField = new JFormattedTextField(floatFormatFactory);
xTextField.setColumns(5);
yTextField.setColumns(5);
zTextField.setColumns(5);
xTextField.setValue(vec != null ? vec.x : 0f);
yTextField.setValue(vec != null ? vec.y : 0f);
zTextField.setValue(vec != null ? vec.z : 0f);
PropertyChangeListener listener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
// TODO Auto-generated method stub
float x = ((Number) xTextField.getValue()).floatValue();
float y = ((Number) yTextField.getValue()).floatValue();
float z = ((Number) zTextField.getValue()).floatValue();
simpleApp.enqueue(() -> {
beanPropAccess.setValue(new Vector3f(x, y, z));
System.out.println("new Vector3f applied: " + new Vector3f(x, y, z));
});
};
};
xTextField.addPropertyChangeListener("value", listener);
yTextField.addPropertyChangeListener("value", listener);
zTextField.addPropertyChangeListener("value", listener);
JPanel panel = new JPanel();
panel.add(new JLabel("x"));
panel.add(xTextField);
panel.add(new JLabel("y"));
panel.add(yTextField);
panel.add(new JLabel("z"));
panel.add(zTextField);
return panel;
}
Probably there is also another bug at file [src/main/java/com/jayfella/devkit/forms/Configuration.java]
at this lines 182… setFrustumFar is repetead twice on frustumNearTextField.getValue() and frustumFarTextField.getValue()
For floats - actually what I want to make is a JSlider with a text field so you can manually input the value and see the value. I think it makes a lot more sense that way.
For the textArea - I haven’t needed one yet but the user can add their own components if they make plugins / appstates. This one may be useful.
Reflections reflections = new Reflections(appState.getClass().getName(), new MethodAnnotationsScanner());
reflections.getMethodsAnnotatedWith(annotationCls);
goes in error if the the appState class have @DevKitAppState annotation, but don’t have any method annotated with one of the properties supported by the devkit (@FloatProperty, …).
org.reflections.ReflectionsException: Scanner MethodAnnotationsScanner was not configured
at org.reflections.Store.get(Store.java:39)
at org.reflections.Store.get(Store.java:61)
at org.reflections.Store.get(Store.java:46)
at org.reflections.Reflections.getMethodsAnnotatedWith(Reflections.java:478)
Maybe it can be better using this code, which do the same things but don’t goes on error: