I recently asked which was the best Swing component to bind to a BigDecimal variable (with some specific editing properties). It turns out that none of the standard Swing components satisfy me completely, as well as the libraries of third-party Swing components that I found there. Therefore, Ive decided to create his own Swing component.
Component Description:
I want to extend a JTextField or JFormattedTextField , so my new component can easily be associated with a BigDecimal variable.
The component will have custom scale and length properties.
Behavior:
When a component is drawn, it shows only the decimal point and space for the scale digits on the right.
When the component receives focus, the caret should be left to the decimal point. Since the user enters numbers (any other character is ignored), they are displayed to the left of the carriage, only scale length numbers are accepted, any other entered number is ignored when the integer part is filled. Each time a user enters a decimal point, the carriage moves to the right side of the decimal point. The following digits are shown in the decimal part: only the scale numbers are considered any other entered number, it is ignored as the decimal part is filled. In addition, thousands of delimiters should be displayed as user numbers left to the decimal point.
I also want to use the component as the Cell Editor in JTable (without having to code it twice).
A call to the getValue () method for the component should give BigDecimal, representing the number just entered.
I have never created my own Swing component; I almost did not use the standard ones. Therefore, I would appreciate a good tutorial / info / tip on creating the described component. This ... this is the only thing I have so far.
Thanks in advance.
mmutilva
source share