[SOLVED] Currency Formated WebTextField

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

[SOLVED] Currency Formated WebTextField

Postby debugger » Sun Sep 14, 2014 10:52 pm

Hello again. I am using WebTextField with format for currency(Euro/Germany). My problem occur when I try to modify or delete the entered value. I am able to delete/modify everything except the first number. Please see code below.

Image

Image




Code: Select all
NumberFormat formatEarnings = NumberFormat.getCurrencyInstance(Locale.GERMANY);
formatEarnings.setMaximumFractionDigits(0);
NumberFormatter formatter = new NumberFormatter(formatEarningsAddClient);
formatter.setMinimum(0.0);
formatter.setMaximum(100000000.0);
formatter.setAllowsInvalid(false);
formatter.setOverwriteMode(true);
earningsField = new WebFormattedTextField(formatter);
earningsField.setValue(0.0);
earningsField.setColumns(10);
c.gridx = 1;
c.gridy = 7;
moreInfoTab.add(earningsField,c);
debugger
 
Posts: 3
Joined: Sun Aug 31, 2014 8:30 pm

Re: Currency Formated WebTextField

Postby mgarin » Mon Sep 15, 2014 10:43 am

Same will happen if you use simple JFormattedTextField:
Code: Select all
public class FormatTest
{
    public static void main ( final String[] args )
    {
        final NumberFormat formatEarnings = NumberFormat.getCurrencyInstance ( Locale.GERMANY );
        formatEarnings.setMaximumFractionDigits ( 0 );
        final NumberFormatter formatter = new NumberFormatter ( formatEarnings );
        formatter.setMinimum ( 0.0 );
        formatter.setMaximum ( 100000000.0 );
        formatter.setAllowsInvalid ( false );
        formatter.setOverwriteMode ( true );

        final JFormattedTextField earningsField = new JFormattedTextField ( formatter );
        earningsField.setValue ( 0.0 );
        earningsField.setColumns ( 10 );

        TestFrame.show ( earningsField, 50 );
    }
}

So this is not a WebLaF issue.

And I actually think that this is a proper behavior based on the pattern you have provided.
It just doesn't allow you to have incorrect value in the field (empty value would be incorrect in this case).
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Currency Formated WebTextField

Postby mgarin » Tue Sep 30, 2014 12:17 pm

Will mark this solved.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron