问题
I need to format jformattedtextfeild for only add double/float values with two decimal places in runtime.
ex: 15600.00
Please help me on this. Thank you.
回答1:
Here's an example on how to do it:
NumberFormat format = DecimalFormat.getInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
format.setRoundingMode(RoundingMode.HALF_UP);
JFormattedTextField myTwoDecimalTextfield = new JFormattedTextField(format);
myTwoDecimalTextfield.setValue(new Float(3.14));
来源:https://stackoverflow.com/questions/27056539/how-to-add-only-double-values-in-jformattedtextfield