use of javax.swing.text.NumberFormatter in project pcgen by PCGen.
the class Utils method buildIntegerField.
/**
* <p>Builds a formatted text field with specified min and max</p>
*
* @param min minimum value
* @param max maximum value
* @return JFormattedTextField
*/
public static JFormattedTextField buildIntegerField(int min, int max) {
java.text.NumberFormat numberFormat = java.text.NumberFormat.getIntegerInstance();
NumberFormatter formatter = new NumberFormatter(numberFormat);
formatter.setMinimum(min);
formatter.setMaximum(max);
final JFormattedTextField returnValue = new JFormattedTextField(formatter);
returnValue.setColumns(3);
returnValue.addPropertyChangeListener(new PropertyChangeListener() {
Border m_originalBorder = returnValue.getBorder();
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName() != null && evt.getPropertyName().equals("editValid")) {
if (evt.getNewValue() != null && evt.getNewValue() instanceof Boolean) {
if (((Boolean) evt.getNewValue()).booleanValue()) {
returnValue.setBorder(m_originalBorder);
} else {
returnValue.setBorder(BorderFactory.createLineBorder(Color.red));
}
}
}
}
});
return returnValue;
}
use of javax.swing.text.NumberFormatter in project pcgen by PCGen.
the class CheckDialog method initDC.
/**
* <p>
* Initializes the DC value
* </p>
*
*/
private void initDC() {
NumberFormatter formatter = new NumberFormatter(new DecimalFormat("##"));
formatter.setValueClass(Integer.class);
m_dc = new JFormattedTextField(formatter);
m_dc.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
m_dc.setValue(m_defaultDC);
JLabel label = new JLabel("DC:");
label.setAlignmentX(Component.RIGHT_ALIGNMENT);
addComponent(m_dc, label);
}
Aggregations