JavaFX ListView display error when using custom list items

I create a dedicated message log that uses ListViewto display each message in one cell.

enter image description here

It basically works, but when I scroll very quickly up and down, strange things happen. As you can see, I select the selected cell and the cell where the mouse is. After scrolling up and down, the highlighted cells are not the ones in which my mouse pointer is, and for some cells, I can not select them by clicking.

I was able to reproduce this in a very simple example. Suppose we have ListViewcustom rows MyListCellthat display these cells with TextFlow. The method is updateItem MyListCellas follows:

@Override
  protected void updateItem(String item, boolean empty) {

    super.updateItem(item, empty);

    if (empty || item == null) {
      setText(null);
      setGraphic(null);
      return;
    }

    TextFlow textFlow = new TextFlow(new Text(item));
    setGraphic(textFlow);
    setText(null);
  }

, factory :

public ObservableList<String > content = FXCollections.observableArrayList();
public ListView<String> listView;

@Override
public void initialize(URL location, ResourceBundle resources) {

    listView.setCellFactory(cb -> new MyListCell());
    listView.setItems(content);
    /* ... /*

( ):

: - , ?

- Ubuntu 14.04 Oracle jdk 1.8.0_25

+4
1

JavaFX, Node SceneGraph, . ListView , .

, TextFlow ListCell : "" updateItem().

TextFlow vs HBox: TextFlow - (word) . , HBox , , (, ListCell).

, Text. (a Node JavaFX Parent Node, WeakHashMap Cache computeIfAbsent )..

+3

Source: https://habr.com/ru/post/1568832/


All Articles