I checked out the Emsemble example for creating your own Cell Factory and it all worked until I took their example of lets say 20 numbers(which allowed for a scroll) and turned it into 3. For some reason when I would run it and run my mouse cursor over the first row in and focus in/out it would turn the cell invisible, then display it...
final ListView<Number> listView = new ListView<>();
listView.setItems(FXCollections.<Number>observableArrayList(
100.00, -12.34, 33.01
));
listView.setCellFactory((ListView<java.lang.Number> list) -> new moneyViewer());
// listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Group root = new Group(listView);
class moneyViewer extends ListCell<Number>
{
@Override
public void updateItem(Number item, boolean empty)
{
super.updateItem(item, empty);
// format the number as if it were a monetary value using the
// formatting relevant to the current locale. This would format
// 43.68 as "$43.68", and -23.67 as "($23.67)"
setText(item == null ? "" : NumberFormat.getCurrencyInstance().format(item));
if (item != null) {
double value = item.doubleValue();
setTextFill(value == 0 ? Color.BLACK :
value < 0 ? Color.RED : Color.GREEN);
}
}
}
final ListView<Number> listView = new ListView<>();
listView.setItems(FXCollections.<Number>observableArrayList(
100.00, -12.34, 33.01
));
listView.setCellFactory((ListView<java.lang.Number> list) -> new moneyViewer());
// listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Group root = new Group(listView);
class moneyViewer extends ListCell<Number>
{
@Override
public void updateItem(Number item, boolean empty)
{
super.updateItem(item, empty);
// format the number as if it were a monetary value using the
// formatting relevant to the current locale. This would format
// 43.68 as "$43.68", and -23.67 as "($23.67)"
setText(item == null ? "" : NumberFormat.getCurrencyInstance().format(item));
if (item != null) {
double value = item.doubleValue();
setTextFill(value == 0 ? Color.BLACK :
value < 0 ? Color.RED : Color.GREEN);
}
}
}