Issue
What im doing wrong here?
i tried to use function replace() on my setOnEditCommit, but not work.
clnVt.setCellValueFactory(new PropertyValueFactory<>("valorVt"));
clnVt.setEditable(true);
clnVt.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
clnVt.setOnEditCommit(new EventHandler<CellEditEvent<GSTabela2, Double>>() {
@Override
public void handle(CellEditEvent<GSTabela2, Double> c) {
Double valor = c.getTableView().getItems().get(c.getTablePosition().getRow()).valorVtProperty().getValue();
String converte = valor.toString().replace(",", ".");
c.getTableView().getItems().get(c.getTablePosition().getRow()).setValorVt(Double.valueOf(converte));
}
});
Then i try to use a DoubleStringConverter implemention:
public class EstilizadoDoubleStringConverter extends DoubleStringConverter {
private final DoubleStringConverter conversor = new DoubleStringConverter();
@Override
public Double fromString(String value) {
try {
value.replace(",", ".");
return conversor.fromString(value);
} catch (NumberFormatException e) {
e.getStackTrace();
}
return -1.0;
}
@Override
public String toString(Double value) {
try {
return conversor.toString(value);
} catch (NumberFormatException e) {
e.getStackTrace();
}
return null;
}
}
If i use a the DoubleStringConverter a get -1.0;
So, my question is. How i can replace the comma to dot?
Solution
I fix with Slaw Hint.
In my implemention of DoubleStringConverter, i change the
private final DoubleStringConverter conversor = new DoubleStringConverter();
to
private final Locale local = Locale.getDefault(Category.FORMAT);
private final NumberStringConverter conversor = new NumberStringConverter(local);
so my whole implemention its now like this.
public class EstilizadoDoubleStringConverter extends DoubleStringConverter {
private final Locale local = Locale.getDefault(Category.FORMAT);
private final NumberStringConverter conversor = new NumberStringConverter(local);
@Override
public Double fromString(String value) {
try {
return conversor.fromString(value).doubleValue();
} catch (NumberFormatException e) {
e.getStackTrace();
}
return -1.0;
}
@Override
public String toString(Double value) {
try {
return conversor.toString(value);
} catch (NumberFormatException e) {
e.getStackTrace();
}
return null;
}
}
Answered By - Thiago Sarkis