Reputation: 91
I've got an application with a fairly large amount (and variety) of swing components. Anyone know if there's a way to set a consistent NumberFormat across all of these components (perhaps via the UIManager?), or am I going to have to extend each component into a custom one with references to a static NumberFormat object?
Thanks!
Upvotes: 2
Views: 117
Reputation: 20755
Try this
code
call=> formatNumber(yourNumber);
code
private String formatNumber(String value) {
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher(value);
NumberFormat nf = NumberFormat.getInstance();
StringBuffer sb = new StringBuffer();
while(m.find()) {
String g = m.group();
m.appendReplacement(sb, nf.format(Double.parseDouble(g)));
}
return m.appendTail(sb).toString();
}
Upvotes: 1