Custom creation method for JFormattedTextField . - Java Swing

Java examples for Swing:JTextField

Description

Custom creation method for JFormattedTextField .

Demo Code


//package com.java2s;

import java.text.NumberFormat;

import javax.swing.JFormattedTextField;
import javax.swing.text.NumberFormatter;

public class Main {
    /**/*www  .j av  a  2s.  com*/
     * Custom creation method for {@link JFormattedTextField}.
     */
    public static JFormattedTextField createIntegerTextField(final int min,
            final int max, final int now, final int columnNumber) {
        final NumberFormatter formatter = new NumberFormatter(
                NumberFormat.getIntegerInstance());
        formatter.setMinimum(min);
        formatter.setMaximum(max);
        final JFormattedTextField TF = new JFormattedTextField(formatter);
        TF.setValue(now);
        TF.setColumns(columnNumber);
        return TF;
    }
}

Related Tutorials