Search in sources :

Example 11 with NumberFormatter

use of javax.swing.text.NumberFormatter in project pcgen by PCGen.

the class Utils method buildIntegerField.

/**
	 * <p>Builds a formatted text field with specified min and max</p>
	 * 
	 * @param min minimum value
	 * @param max maximum value
	 * @return JFormattedTextField
	 */
public static JFormattedTextField buildIntegerField(int min, int max) {
    java.text.NumberFormat numberFormat = java.text.NumberFormat.getIntegerInstance();
    NumberFormatter formatter = new NumberFormatter(numberFormat);
    formatter.setMinimum(min);
    formatter.setMaximum(max);
    final JFormattedTextField returnValue = new JFormattedTextField(formatter);
    returnValue.setColumns(3);
    returnValue.addPropertyChangeListener(new PropertyChangeListener() {

        Border m_originalBorder = returnValue.getBorder();

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName() != null && evt.getPropertyName().equals("editValid")) {
                if (evt.getNewValue() != null && evt.getNewValue() instanceof Boolean) {
                    if (((Boolean) evt.getNewValue()).booleanValue()) {
                        returnValue.setBorder(m_originalBorder);
                    } else {
                        returnValue.setBorder(BorderFactory.createLineBorder(Color.red));
                    }
                }
            }
        }
    });
    return returnValue;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JFormattedTextField(javax.swing.JFormattedTextField) Border(javax.swing.border.Border) NumberFormatter(javax.swing.text.NumberFormatter)

Example 12 with NumberFormatter

use of javax.swing.text.NumberFormatter in project pcgen by PCGen.

the class CheckDialog method initDC.

/**
	 * <p>
	 * Initializes the DC value
	 * </p>
	 *
	 */
private void initDC() {
    NumberFormatter formatter = new NumberFormatter(new DecimalFormat("##"));
    formatter.setValueClass(Integer.class);
    m_dc = new JFormattedTextField(formatter);
    m_dc.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
    m_dc.setValue(m_defaultDC);
    JLabel label = new JLabel("DC:");
    label.setAlignmentX(Component.RIGHT_ALIGNMENT);
    addComponent(m_dc, label);
}
Also used : DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) NumberFormatter(javax.swing.text.NumberFormatter)

Aggregations

NumberFormatter (javax.swing.text.NumberFormatter)12 JFormattedTextField (javax.swing.JFormattedTextField)8 DecimalFormat (java.text.DecimalFormat)4 DefaultFormatterFactory (javax.swing.text.DefaultFormatterFactory)4 JLabel (javax.swing.JLabel)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 JPanel (javax.swing.JPanel)2 Border (javax.swing.border.Border)2 ExtrapolationMethod (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.ExtrapolationMethod)1 RedistributionMode (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionMode)1 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 InitHolder (gmgen.plugin.InitHolder)1 PcgCombatant (gmgen.plugin.PcgCombatant)1 Component (java.awt.Component)1 FlowLayout (java.awt.FlowLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1