use of javax.swing.text.DefaultFormatterFactory in project intellij-community by JetBrains.
the class SingleIntegerFieldOptionsPanel method setupIntegerFieldTrackingValue.
/**
* Sets integer number format to JFormattedTextField instance,
* sets value of JFormattedTextField instance to object's field value,
* synchronizes object's field value with the value of JFormattedTextField instance.
*
* @param textField JFormattedTextField instance
* @param owner an object whose field is synchronized with {@code textField}
* @param property object's field name for synchronization
*/
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField, final InspectionProfileEntry owner, final String property) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
textField.setValue(getPropertyValue(owner, property));
final Document document = textField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
textField.commitEdit();
setPropertyValue(owner, property, ((Number) textField.getValue()).intValue());
} catch (ParseException e1) {
// No luck this time
}
}
});
}
use of javax.swing.text.DefaultFormatterFactory in project jgnash by ccavanaugh.
the class CheckDesignDialog method getFloatField.
private static JFormattedTextField getFloatField() {
NumberFormatter df = new NumberFormatter(new DecimalFormat("#.##"));
NumberFormatter ef = new NumberFormatter(new DecimalFormat("#.##"));
return new JFormattedTextField(new DefaultFormatterFactory(df, df, ef));
}
use of javax.swing.text.DefaultFormatterFactory in project jgnash by ccavanaugh.
the class CheckDesignDialog method getIntegerField.
private static JFormattedTextField getIntegerField() {
NumberFormatter df = new NumberFormatter(new DecimalFormat("#"));
NumberFormatter ef = new NumberFormatter(new DecimalFormat("#"));
return new JFormattedTextField(new DefaultFormatterFactory(df, df, ef));
}
use of javax.swing.text.DefaultFormatterFactory in project jdk8u_jdk by JetBrains.
the class ValueFormatter method init.
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
use of javax.swing.text.DefaultFormatterFactory in project sic by belluccifranco.
the class RenderTabla method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : null);
this.setBackground(isSelected ? UIManager.getColor("Table.selectionBackground") : UIManager.getColor("Table.background"));
this.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(new DecimalFormat("##,##0.00"))));
this.setHorizontalAlignment(SwingConstants.RIGHT);
Double valor = null;
if (value instanceof Double) {
valor = (Double) value;
}
this.setValue(valor);
return this;
}
Aggregations