Package javax.swing.text

Examples of javax.swing.text.NumberFormatter


            format.setMaximumFractionDigits(0);
            format.setMinimumIntegerDigits(0);
            format.setMaximumIntegerDigits(5);
            format.setParseIntegerOnly(true);
            format.setDecimalSeparatorAlwaysShown(false);
            NumberFormatter nf = new NumberFormatter(format);
            nf.setMinimum(new Integer(1));
            nf.setMaximum(new Integer(Integer.MAX_VALUE));
            nf.setAllowsInvalid(true);
            nf.setCommitsOnValidEdit(true);
            tfRangeFrom = new JFormattedTextField(nf);
            tfRangeFrom.setColumns(4);
            tfRangeFrom.setEnabled(false);
            tfRangeFrom.addActionListener(this);
            tfRangeFrom.addFocusListener(this);
            tfRangeFrom.setFocusLostBehavior(
                JFormattedTextField.PERSIST);
            pnlBottom.add(tfRangeFrom);
            lblRangeTo = new JLabel(getMsg("label.rangeto"));
            lblRangeTo.setEnabled(false);
            pnlBottom.add(lblRangeTo);
            NumberFormatter nfto;
            try {
                nfto = (NumberFormatter)nf.clone();
            } catch (CloneNotSupportedException e) {
                nfto = new NumberFormatter();
            }
            tfRangeTo = new JFormattedTextField(nfto);
            tfRangeTo.setColumns(4);
            tfRangeTo.setEnabled(false);
            tfRangeTo.addFocusListener(this);
View Full Code Here


            format.setMinimumFractionDigits(1);
            format.setMaximumFractionDigits(2);
            format.setMinimumIntegerDigits(1);
            format.setParseIntegerOnly(false);
            format.setDecimalSeparatorAlwaysShown(true);
            NumberFormatter nf = new NumberFormatter(format);
            nf.setMinimum(new Float(0.0f));
            nf.setMaximum(new Float(999.0f));
            nf.setAllowsInvalid(true);
            nf.setCommitsOnValidEdit(true);

            leftMargin = new JFormattedTextField(nf);
            leftMargin.addFocusListener(this);
            leftMargin.addActionListener(this);
            rightMargin = new JFormattedTextField(nf);
View Full Code Here

      JFormattedTextField.AbstractFormatter formatter = null;
      Format numberFormat = null;
      Object value = null;
      if ( attribValueLwr.equals( "integer" )) {
        numberFormat = NumberFormat.getIntegerInstance();
        formatter = new NumberFormatter( (NumberFormat)numberFormat );
        value = new Integer( 0 );
      }
      else if ( attribValueLwr.equals( "currency" )) {
        numberFormat = NumberFormat.getCurrencyInstance( Locale.getDefault());
        formatter = new NumberFormatter( (NumberFormat)numberFormat );
      }
      else if ( attribValueLwr.equals( "decimal"))  {
        numberFormat = DecimalFormat.getNumberInstance();
        formatter = new NumberFormatter( (NumberFormat)numberFormat );
        value = new Double( 0.0 );
      }
      else if ( attribValueLwr.equals( "date")) {
        numberFormat = DateFormat.getDateInstance();
        formatter = new DateFormatter( (DateFormat)numberFormat );     
View Full Code Here

            }
            for (int i = 1; i <= fraction; i++) {
                sb.append("0");
            }
            DecimalFormat df = new DecimalFormat(sb.toString());
            NumberFormatter nf = new NumberFormatter(df);
            DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
            ((JFormattedTextField)childComponent).setFormatterFactory(factory);
        }
       
        ((JComboBox)component).addActionListener(
                new ActionAdapter() {
           
                    public void actionPerformed(ActionEvent e) {
                       
                        if (ComponentManager.getValue(component) != null) {
                            CurrencyPlugin cp = CurrencyPlugin.getInstance();
                            StringBuffer sb = new StringBuffer("###" + cp.getSepor() + "###");
                            int fraction = cp.getFraction(ComponentManager.getValue(component).toString());
                            if (fraction > 0) {
                                sb.append(cp.getFpoint());
                            }
                            for (int i = 1; i <= fraction; i++) {
                                sb.append("0");
                            }
                            DecimalFormat df = new DecimalFormat(sb.toString());
                            NumberFormatter nf = new NumberFormatter(df);
                            DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                            ((JFormattedTextField)childComponent).setFormatterFactory(factory);
                        }
                       
                    }
View Full Code Here

            }
            for (int i = 1; i <= fraction; i++) {
                sb.append("0");
            }
            DecimalFormat df = new DecimalFormat(sb.toString());
            NumberFormatter nf = new NumberFormatter(df);
            DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
            ((JFormattedTextField)childComponent).setFormatterFactory(factory);
        }
       
        ((JComboBox)component).addActionListener(
                new ActionAdapter() {
           
                    public void actionPerformed(ActionEvent e) {
                                               
                        if (ComponentManager.getValue(component) != null) {
                            CurrencyPlugin cp = CurrencyPlugin.getInstance();
                            UomPlugin up = UomPlugin.getInstance();
                            StringBuffer sb = new StringBuffer("###" + cp.getSepor() + "###");
                            int fraction = up.getFraction(ComponentManager.getValue(component).toString());
                            if (fraction > 0) {
                                sb.append(".");
                            }
                            for (int i = 1; i <= fraction; i++) {
                                sb.append("0");
                            }
                            DecimalFormat df = new DecimalFormat(sb.toString());
                            NumberFormatter nf = new NumberFormatter(df);
                            DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                            ((JFormattedTextField)childComponent).setFormatterFactory(factory);
                        }
                       
                    }
View Full Code Here

        } else if (component instanceof JTextField) {
            JTextField textField = (JTextField)component;
            if (component instanceof JFormattedTextField) {
                JFormattedTextField ftf = (JFormattedTextField)textField;
                if (ftf.getFormatter() instanceof NumberFormatter) {
                    NumberFormatter nf = (NumberFormatter)ftf.getFormatter();
                    try {
                        value = nf.stringToValue(ftf.getText());
                    } catch (Exception e) {
                        //e.printStackTrace();
                    }
                } else {
                    value = ((JFormattedTextField)textField).getValue();
View Full Code Here

                                }
                                for (int i = 1; i <= fraction; i++) {
                                    sb.append("0");
                                }
                                DecimalFormat df = new DecimalFormat(sb.toString());
                                NumberFormatter nf = new NumberFormatter(df);
                                DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                                ((JFormattedTextField)cComponent).setFormatterFactory(factory);
                            }

                        }
View Full Code Here

                                }
                                for (int i = 1; i <= fraction; i++) {
                                    sb.append("0");
                                }
                                DecimalFormat df = new DecimalFormat(sb.toString());
                                NumberFormatter nf = new NumberFormatter(df);
                                DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                                ((JFormattedTextField)cComponent).setFormatterFactory(factory);
                            }

                        }
View Full Code Here

                    }
                    for (int i = 1; i <= fraction; i++) {
                        sb.append("0");
                    }
                    DecimalFormat df = new DecimalFormat(sb.toString());
                    NumberFormatter nf = new NumberFormatter(df);
                    DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                    ((JFormattedTextField)component).setFormatterFactory(factory);
                } else if (childColumn.getInputType() == 12) {
                    JComponent component = childComponentExt.getComponent();
                    CurrencyPlugin cp = CurrencyPlugin.getInstance();
                    UomPlugin up = UomPlugin.getInstance();
                    if (column.getPControls() != null) {
                        StringTokenizer st = new StringTokenizer(column.getPControls(), ".");
                        String tableName = (String)st.nextElement();
                        String columnName = (String)st.nextElement();
                        ComponentExt pComponentExt = relationManager.findComponentExt(tableName, columnName);
                        Object pValue = ComponentManager.getValue(pComponentExt.getComponent());
                        StringBuffer sb = new StringBuffer("###" + cp.getSepor() + "###");
                        int fraction = Integer.parseInt(GlobalValueManager.getValue("APPLIATION.DEFFRACTION"));
                        if (pValue != null)
                            fraction = up.getFraction(pValue.toString());
                        if (fraction > 0) {
                            sb.append(".");
                        }
                        for (int i = 1; i <= fraction; i++) {
                            sb.append("0");
                        }
                        DecimalFormat df = new DecimalFormat(sb.toString());
                        NumberFormatter nf = new NumberFormatter(df);
                        DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                        ((JFormattedTextField)component).setFormatterFactory(factory);
                    }                           
                }
            }   
View Full Code Here

                        }
                        for (int i = 1; i <= fraction; i++) {
                            sb.append("0");
                        }
                        DecimalFormat df = new DecimalFormat(sb.toString());
                        NumberFormatter nf = new NumberFormatter(df);
                        DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                        ((JFormattedTextField)component).setFormatterFactory(factory);
                    } else if (childColumn.getInputType() == 12) {
                        JComponent component = childComponentExt.getComponent();
                        CurrencyPlugin cp = CurrencyPlugin.getInstance();
                        UomPlugin up = UomPlugin.getInstance();
                        StringTokenizer st = new StringTokenizer(column.getPControls(), ".");
                        String tableName = (String)st.nextElement();
                        String columnName = (String)st.nextElement();
                        ComponentExt pComponentExt = relationManager.findComponentExt(tableName, columnName);
                        Object pValue = ComponentManager.getValue(pComponentExt.getComponent());
                        StringBuffer sb = new StringBuffer("###" + cp.getSepor() + "###");
                        int fraction = Integer.parseInt(GlobalValueManager.getValue("APPLIATION.DEFFRACTION"));
                        if (pValue != null)
                            fraction = up.getFraction(pValue.toString());
                        if (fraction > 0) {
                            sb.append(".");
                        }
                        for (int i = 1; i <= fraction; i++) {
                            sb.append("0");
                        }
                        DecimalFormat df = new DecimalFormat(sb.toString());
                        NumberFormatter nf = new NumberFormatter(df);
                        DefaultFormatterFactory factory = new DefaultFormatterFactory(nf);
                        ((JFormattedTextField)component).setFormatterFactory(factory);
                    }
                }
           
View Full Code Here

TOP

Related Classes of javax.swing.text.NumberFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.