
se.wfh.libs.common.gui.widgets.WCurrencyTextField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gui Show documentation
Show all versions of gui Show documentation
Some helper classes i needed for several projects (GUI / Swing parts)
The newest version!
package se.wfh.libs.common.gui.widgets;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
public class WCurrencyTextField extends AbstractWTextField {
private static DecimalFormat getFormat() {
DecimalFormat formatter = (DecimalFormat) NumberFormat
.getCurrencyInstance();
DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
symbols.setCurrencySymbol("");
formatter.setDecimalFormatSymbols(symbols);
formatter.setNegativeSuffix("");
formatter.setPositiveSuffix("");
return formatter;
}
private static final long serialVersionUID = 1L;
public WCurrencyTextField() {
this(null, 10);
}
public WCurrencyTextField(final Double defval) {
this(defval, 10);
}
public WCurrencyTextField(final Double defval, final int columns) {
super(WCurrencyTextField.getFormat(), defval, columns);
addCurrencyLabel();
}
private void addCurrencyLabel() {
NumberFormat orig = NumberFormat.getCurrencyInstance();
String complete = orig.format(10);
String symbol = orig.getCurrency().getSymbol();
boolean prefix = complete.indexOf(symbol) < 2;
WLabel lblCurrency = new WLabel(symbol);
if (prefix) {
add(lblCurrency, 0);
} else {
add(lblCurrency);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy