1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| energyStep = new JTextField()
{
private String tt;
public void setText(String t) {
try {
tt = t/*String.format("%6.4f",t.replace(',', '.'))*/;
String t2 = String.format("%6.4f",Double.parseDouble(t.replace(',', '.')));
Document doc = getDocument();
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).replace(0, doc.getLength(), t2.replace(',', '.'),null);
}
else {
doc.remove(0, doc.getLength());
doc.insertString(0, t2.replace(',', '.'), null);
}
} catch (BadLocationException e) {
//UIManager.getLookAndFeel().provideErrorFeedback(JTextComponent.this);
}
}
public String getText() {
return tt;
}
}; |
Partager