Recently I asked which was the best Swing component to bind to a BigDecimal variable (with some particular editing properties). It turns out that none of the standard Swing components suit me completely, nor did the third-party Swing component libraries I've found out there. So I’ve decided to create my own Swing component.
Component description:
I want to extend JTextField or JFormattedTextField, so my new component can be easily bound to a BigDecimal variable.
The component will have customizable scale and length properties.
Behavior:
When the component is drawn, it shows only the decimal point and space for scale digits to its right.
When the component receives focus the caret should be positioned left to the decimal point. As the user types numbers (any other character is ignored) they appear to the left of the caret, only length – scale numbers are accepted, any other number typed is ignored as the integer portion is full. Any time the user types the decimal point the caret moves to the right side of the decimal point. The following numbers typed are shown in the decimal part, only scale numbers are considered any other number typed is ignored as the decimal portion is full. Additionally, thousand separators should appear as the user types numbers left to the decimal point.
I also want to be able to use the component as a Cell Editor in a JTable (without having to code it twice).
Invoking a getValue() method on the component should yield the BigDecimal representing the number just entered.
I’ve never created my own Swing component; I’ve barely used the standard ones. So I would appreciate any good tutorial/info/tip on creating the component described. This is the only thing I've got so far.
Thanks in advance.