A BigDecimal object custom formatter : Formatted TextField « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing JFC » Formatted TextFieldScreenshots 
A BigDecimal object custom formatter
  


import java.math.BigDecimal;
import java.text.DecimalFormat;

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

public class Main {
  public static void main(String[] argv) {
    JFormattedTextField f = new JFormattedTextField(new BigDecimal("123.4567"));
    DefaultFormatter fmt = new NumberFormatter(new DecimalFormat("#.0###############"));
    fmt.setValueClass(f.getValue().getClass());
    DefaultFormatterFactory fmtFactory = new DefaultFormatterFactory(fmt, fmt, fmt);
    f.setFormatterFactory(fmtFactory);

    BigDecimal bigValue = (BigDecimalf.getValue();

  }
}

   
    
  
Related examples in the same category
1. different configurations of JFormattedTextField: Numberdifferent configurations of JFormattedTextField: Number
2. Different configurations of JFormattedTextField: DateDifferent configurations of JFormattedTextField: Date
3. JFormattedTextField: an input mask (###) ###-#### for a telephone number
4. Using an InputVerifier with a formatted textfieldUsing an InputVerifier with a formatted textfield
5. A formatter for regular expressions to be used with JFormattedTextFieldA formatter for regular expressions to be used with JFormattedTextField
6. Field with different formats with focus and withoutField with different formats with focus and without
7. Input: any number of hyphen-delimeted numbers. Output: int arrayInput: any number of hyphen-delimeted numbers. Output: int array
8. A quick demonstration of JFormattedTextFieldA quick demonstration of JFormattedTextField
9. Formatter Factory DemoFormatter Factory Demo
10. Formatted TextField DemoFormatted TextField Demo
11. Accepting Formatted InputAccepting Formatted Input
12. Formatted TextField ExampleFormatted TextField Example
13. Input Verification Demo Input Verification Demo
14. Creating a Text Field to Display and Edit a Phone Number
15. Creating a Text Field to Display and Edit a social security number
16. Make custom Input Text Formatter in Java
17. Support a date with the custom format: 2009-1-1
18. A decimal number with one digit following the decimal point;
19. Dynamically change the format
20. Creating a Text Field to Display and Edit a Number
21. Creating a Text Field to Display and Edit a Date
22. Format and validate input field in Java Swing
23. Input Verification Dialog Demo Input Verification Dialog Demo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.