Java Code Examples for javax.swing.JFormattedTextField#getFormatter()
The following examples show how to use
javax.swing.JFormattedTextField#getFormatter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberEditor.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
public NumberEditor(String fieldName, Object obj, Field field, int index, Class<?> type, SWFType swfType) { setSize(100, getSize().height); setMaximumSize(getSize()); this.obj = obj; this.field = field; this.index = index; this.type = type; this.swfType = swfType; this.fieldName = fieldName; reset(); JFormattedTextField jtf = ((JSpinner.NumberEditor) getEditor()).getTextField(); DefaultFormatter formatter = (DefaultFormatter) jtf.getFormatter(); formatter.setCommitsOnValidEdit(true); }
Example 2
Source File: IntegerSpinner.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** Instantiates a new value spinner. */ public IntegerSpinner(int min, int max, int stepSize) { SpinnerNumberModel model = new SpinnerNumberModel(min, min, max, stepSize); setModel(model); JComponent comp = getEditor(); final JFormattedTextField field = (JFormattedTextField) comp.getComponent(0); DefaultFormatter formatter = (DefaultFormatter) field.getFormatter(); formatter.setCommitsOnValidEdit(true); addChangeListener( new ChangeListener() { private double oldValue = Double.MAX_VALUE; @Override public void stateChanged(ChangeEvent e) { Double doubleValue = IntegerSpinner.this.getDoubleValue(); if (doubleValue != oldValue) { double oldValueCopy = oldValue; oldValue = doubleValue; if (minIsZero && (doubleValue < 0.0)) { doubleValue = 0.0; field.setValue(doubleValue); } notifyListeners(oldValueCopy, doubleValue); } } }); }
Example 3
Source File: DecimalSpinner.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates the ui. * * @param initialValue the initial value * @param min the minimum value * @param max the maximum value * @param stepSize the step size * @param noOfDecimalPlaces the number of decimal places */ private void createUI( Double initialValue, Double min, Double max, Double stepSize, double noOfDecimalPlaces) { SpinnerNumberModel model = new SpinnerNumberModel(initialValue, min, max, stepSize); setModel(model); JSpinner.NumberEditor editor = (JSpinner.NumberEditor) getEditor(); DecimalFormat format = editor.getFormat(); format.setMinimumFractionDigits((int) noOfDecimalPlaces); final JFormattedTextField field = editor.getTextField(); DefaultFormatter formatter = (DefaultFormatter) field.getFormatter(); formatter.setCommitsOnValidEdit(true); addChangeListener( new ChangeListener() { private double oldValue = Double.MAX_VALUE; @Override public void stateChanged(ChangeEvent e) { Double doubleValue = DecimalSpinner.this.getDoubleValue(); if (doubleValue != oldValue) { double oldValueCopy = oldValue; oldValue = doubleValue; if (minIsZero && (doubleValue < 0.0)) { doubleValue = 0.0; field.setValue(doubleValue); } notifyListeners(oldValueCopy, doubleValue); } } }); }