本文整理匯總了Java中javax.swing.text.DefaultFormatterFactory類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultFormatterFactory類的具體用法?Java DefaultFormatterFactory怎麽用?Java DefaultFormatterFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultFormatterFactory類屬於javax.swing.text包,在下文中一共展示了DefaultFormatterFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: WettDialog
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
/**
* Creates a new WettDialog and displays the given array of snails.
* @param parent The Form opening this dialog
* @param schneggen The array of snails to display
* @param wettbueroFactor The factor the Wettbuero uses.
*/
public WettDialog(Frame parent, ArrayList<Rennschnecke> schneggen, double wettbueroFactor) {
super(parent, true);
initComponents();
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
NumberFormatter nf = new NumberFormatter(format);
nf.setMinimum(0.02);
// The maximum bet value is, well, pretty high.
nf.setMaximum(Double.MAX_VALUE / wettbueroFactor);
nf.setAllowsInvalid(false);
nf.setCommitsOnValidEdit(true);
nf.setOverwriteMode(false);
einsatzInput.setFormatterFactory(
new DefaultFormatterFactory(nf)
);
result = null;
snailList.setModel(new DefaultListModel<>());
snailList.setListData(schneggen.toArray(new Rennschnecke[schneggen.size()]));
}
示例2: rebuildSelf
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
@Override
protected void rebuildSelf(FlexGrid grid, FlexRow right) {
ContainedWeightReduction feature = (ContainedWeightReduction) getFeature();
FlexRow row = new FlexRow();
row.add(addChangeBaseTypeCombo());
EditorField field = new EditorField(new DefaultFormatterFactory(new WeightReductionFormatter()), (event) -> {
EditorField source = (EditorField) event.getSource();
if ("value".equals(event.getPropertyName())) { //$NON-NLS-1$
feature.setValue(source.getValue());
notifyActionListeners();
}
}, SwingConstants.LEFT, feature.getValue(), new WeightValue(999999999, SheetPreferences.getWeightUnits()), WEIGHT_OR_PERCENTAGE);
UIUtilities.setOnlySize(field, field.getPreferredSize());
add(field);
row.add(field);
row.add(new FlexSpacer(0, 0, true, false));
grid.add(row, 0, 0);
}
示例3: NumberPropertyEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public NumberPropertyEditor(Class type) {
if (!Number.class.isAssignableFrom(type)) {
throw new IllegalArgumentException("type must be a subclass of Number");
}
editor = new JFormattedTextField();
this.type = type;
((JFormattedTextField)editor).setValue(getDefaultValue());
((JFormattedTextField)editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);
// use a custom formatter to have numbers with up to 64 decimals
NumberFormat format = NumberConverters.getDefaultFormat();
((JFormattedTextField) editor).setFormatterFactory(
new DefaultFormatterFactory(new NumberFormatter(format))
);
}
示例4: IntegerEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
/**
* Construct a <code>JSpinner</code> editor that supports displaying and
* editing the value of a <code>SpinnerIntModel</code> with a
* <code>JFormattedTextField</code>. <code>This</code>
* <code>IntegerEditor</code> becomes both a <code>ChangeListener</code>
* on the spinner and a <code>PropertyChangeListener</code> on the new
* <code>JFormattedTextField</code>.
*
* @param spinner the spinner whose model <code>this</code> editor will
* monitor
* @param format the <code>NumberFormat</code> object that's used to
* display and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not an
* instance of <code>SpinnerIntModel</code>
*
* @see #getTextField
* @see SpinnerIntModel
* @see java.text.DecimalFormat
*/
private IntegerEditor(JSpinner spinner, NumberFormat format) {
super(spinner);
if (!(spinner.getModel() instanceof SpinnerIntModel)) {
throw new IllegalArgumentException("model not a SpinnerIntModel");
}
format.setGroupingUsed(false);
format.setMaximumFractionDigits(0);
SpinnerIntModel model = (SpinnerIntModel) spinner.getModel();
NumberFormatter formatter = new IntegerEditorFormatter(model, format);
DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
JFormattedTextField ftf = getTextField();
ftf.setEditable(true);
ftf.setFormatterFactory(factory);
ftf.setHorizontalAlignment(JTextField.RIGHT);
try {
String minString = formatter.valueToString(model.getMinimum());
String maxString = formatter.valueToString(model.getMaximum());
// Trying to approximate the width difference between "m" and "0" by multiplying with 0.7
ftf.setColumns((int) Math.round(0.7 * Math.max(maxString.length(), minString.length())));
} catch (ParseException e) {
// Nothing to do, the component width will simply be the default
}
}
示例5: DateEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public DateEditor() {
super( new JFormattedTextField() );
textField = (JFormattedTextField) getComponent();
textField.setFormatterFactory( new DefaultFormatterFactory( new DateFormatter( Entry.LOAD_FORMAT ) ) );
textField.setFocusLostBehavior( JFormattedTextField.PERSIST );
textField.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "check" );
textField.getActionMap().put( "check", new AbstractAction() {
public void actionPerformed( ActionEvent e ) {
if ( !textField.isEditValid() ) { //The text is invalid.
if ( userSaysRevert() ) { //reverted
textField.postActionEvent(); //inform the editor
}
}
else {
try { //The text is valid,
textField.commitEdit(); //so use it.
textField.postActionEvent(); //stop editing
}
catch ( java.text.ParseException exc ) {
}
}
}
} );
}
示例6: init
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
/**
* Affiche le paneau de selection de la date au clic de souris
*/
private void init() {
obj = this;
getEditor().addMouseListener(mouseListener);
DatePickerFormatter formatter = new DatePickerFormatter(
// invers sequence for parsing to satisfy the year parsing rules
new DateFormat[] { shortFormat, longFormat }) {
@Override
public String valueToString(Object value) throws ParseException {
if (value == null)
return null;
return getFormats()[1].format(value);
}
};
DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
getEditor().setFormatterFactory(factory);
setFormats(formats);
getEditor().setDisabledTextColor(Color.BLACK);
}
示例7: setupIntegerFieldTrackingValue
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
/**
* 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
}
}
});
}
示例8: NumberPropertyEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public NumberPropertyEditor(Class<?> type) {
if (!Number.class.isAssignableFrom(type)) {
throw new IllegalArgumentException("type must be a subclass of Number");
}
editor = new JFormattedTextField();
this.type = type;
((JFormattedTextField) editor).setValue(getDefaultValue());
((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);
// use a custom formatter to have numbers with up to 64 decimals
NumberFormat format = NumberConverters.DEFAULT_FORMAT;
((JFormattedTextField) editor).setFormatterFactory(
new DefaultFormatterFactory(new NumberFormatter(format))
);
}
示例9: initFormats
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
private void initFormats() {
nfInteger = NumberFormat.getIntegerInstance();
NumberFormatter nf = new NumberFormatter(nfInteger);
nf.setMaximum(Server.MAX_PORT_INDEX);
nf.setMinimum(0);
NumberFormat editFormat = NumberFormat.getIntegerInstance();
editFormat.setGroupingUsed(false);
NumberFormatter editFormatter = new NumberFormatter(editFormat);
editFormatter.setMaximum(Server.MAX_PORT_INDEX);
editFormatter.setMinimum(0);
integerFormatter = new DefaultFormatterFactory(nf, nf, editFormatter, nf);
port.setFormatterFactory(integerFormatter);
port.setValue(28015);
refreshFrequency.setFormatterFactory(integerFormatter);
refreshFrequency.setValue(1);
}
示例10: BigIntegerEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public BigIntegerEditor() {
Class t = BigInteger.class;
if (!Number.class.isAssignableFrom(t)) {
throw new IllegalArgumentException("type must be a subclass of Number");
}
editor = new JFormattedTextField();
this.type = t;
((JFormattedTextField) editor).setValue(getDefaultValue());
((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);
// use a custom formatter to have numbers with up to 64 decimals
format = NumberConverters.getDefaultFormat();
((JFormattedTextField) editor).setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(format)));
}
示例11: BigDecimalEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public BigDecimalEditor() {
Class t = BigDecimal.class;
if (!Number.class.isAssignableFrom(t)) {
throw new IllegalArgumentException("type must be a subclass of Number");
}
editor = new JFormattedTextField();
this.type = t;
((JFormattedTextField) editor).setValue(getDefaultValue());
((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);
// use a custom formatter to have numbers with up to 64 decimals
format = NumberConverters.getDefaultFormat();
((JFormattedTextField) editor).setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(format)));
}
示例12: editStackSize
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public static Dimension editStackSize(Dimension currentSize, Component parent) {
StackSizeEditor dialog = new StackSizeEditor();
dialog.stackDimension = currentSize;
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
dialog.newHeight.setFormatterFactory(new DefaultFormatterFactory(formatter));
dialog.newWidth.setFormatterFactory(new DefaultFormatterFactory(formatter));
dialog.currentStackSize.setText("Stack is " + currentSize.width + "px by " + currentSize.height + "px");
dialog.newWidth.setText(String.valueOf(currentSize.width));
dialog.newHeight.setText(String.valueOf(currentSize.height));
dialog.pack();
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
return dialog.stackDimension;
}
示例13: SpinnerNumberEditor
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
/**
* Constructor.
* Sets the DefaultFormatterFactory created based on {@link
* NumberEditorFormatter} in the text field.
* @param spinner the spinner for which this editor is used
* @param format the format of the numbers shown in the spinner
*/
public SpinnerNumberEditor(JSpinner spinner, DecimalFormat format) {
super(spinner);
if (!(spinner.getModel() instanceof BoundedSpinnerModel)) {
throw new IllegalArgumentException(
"model not a BoundedSpinnerModel");
}
BoundedSpinnerModel model = (BoundedSpinnerModel) spinner.getModel();
NumberFormatter formatter = new NumberEditorFormatter(model, format);
DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
JFormattedTextField ftf = getTextField();
ftf.setEditable(true);
ftf.setFormatterFactory(factory);
ftf.setHorizontalAlignment(JTextField.RIGHT);
try {
String maxString = formatter.valueToString(model.getMinimum());
String minString = formatter.valueToString(model.getMaximum());
ftf.setColumns(Math.max(maxString.length(),minString.length()));
} catch (ParseException e) {
}
}
示例14: testCreateFormattersFactory
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
public void testCreateFormattersFactory() {
DefaultFormatterFactory factory;
tf.setValue(new Integer(34));
factory = getFactoryIfDefault(tf.getFormatterFactory());
assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
//TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
// or factory.getEditFormatter().
assertNull(factory.getNullFormatter());
tf.setFormatterFactory(null);
tf.setValue(new Date());
factory = getFactoryIfDefault(tf.getFormatterFactory());
assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
assertNull(factory.getDisplayFormatter());
assertNull(factory.getEditFormatter());
assertNull(factory.getNullFormatter());
tf.setFormatterFactory(null);
tf.setValue("sdffsdf");
factory = getFactoryIfDefault(tf.getFormatterFactory());
checkDefaultFormatter(factory);
tf.setFormatterFactory(null);
tf.setValue(Color.RED);
factory = getFactoryIfDefault(tf.getFormatterFactory());
checkDefaultFormatter(factory);
}
示例15: ScheduleDurationField
import javax.swing.text.DefaultFormatterFactory; //導入依賴的package包/類
/**
* @param value the duration to use for the initial value, may not be null
*/
public ScheduleDurationField(final Duration value) {
setInputVerifier(new TimeVerifier());
try {
final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
mf.setPlaceholderCharacter('_');
mf.setValueClass(String.class);
final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
setFormatterFactory(dff);
} catch (final ParseException pe) {
throw new FLLInternalException("Invalid format for MaskFormatter", pe);
}
setDuration(value);
}