Search in sources :

Example 1 with DefaultFormatterFactory

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
            }
        }
    });
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) ParseException(java.text.ParseException) Document(javax.swing.text.Document) DocumentEvent(javax.swing.event.DocumentEvent) NumberFormat(java.text.NumberFormat) NumberFormatter(javax.swing.text.NumberFormatter)

Example 2 with DefaultFormatterFactory

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));
}
Also used : DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter)

Example 3 with DefaultFormatterFactory

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));
}
Also used : DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter)

Example 4 with DefaultFormatterFactory

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);
}
Also used : DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory)

Example 5 with DefaultFormatterFactory

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;
}
Also used : DecimalFormat(java.text.DecimalFormat) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter)

Aggregations

DefaultFormatterFactory (javax.swing.text.DefaultFormatterFactory)11 NumberFormatter (javax.swing.text.NumberFormatter)7 DecimalFormat (java.text.DecimalFormat)5 ParseException (java.text.ParseException)3 NumberFormat (java.text.NumberFormat)2 JFormattedTextField (javax.swing.JFormattedTextField)2 RegExFormatter (com.intellij.codeInspection.ui.RegExFormatter)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 RegexFormatter (io.github.satr.idea.plugin.connector.la.ui.components.RegexFormatter)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DefaultFormatter (javax.swing.text.DefaultFormatter)1 Document (javax.swing.text.Document)1 NotNull (org.jetbrains.annotations.NotNull)1