0
ListView<ChatModel> listView;
ObservableList<ChatModel> items = FXCollections.observableArrayList();
private final Image IMAGE_MEN = new Image("men.png");
private final Image IMAGE_WOMEN = new Image("women.png");
private Image[] listOfImages = {IMAGE_MEN, IMAGE_WOMEN};
listView = new ListView<ChatModel>();
listView.setPrefHeight(550);
listView.setItems(items);
listView.setCellFactory(param -> new ListCell<ChatModel>() {
private ImageView imageView = new ImageView();
@Override
public void updateItem(ChatModel name, boolean empty) {
super.updateItem(name, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (name.getClientName().equals("testing"))
imageView.setImage(listOfImages[0]);
else if (name.getClientName().equals("testing1"))
imageView.setImage(listOfImages[1]);
setText(name.getClientMessage());
setGraphic(imageView);
}
}
});
我,我用上面代碼中使用的圖像在ListView添加的項目和文本它工作正常,但在列表視圖中的設計在左在所有的行中。我有一個要求,交替行應該有不同的設計。下一行應該有右側元素。形象與ListView中的文本在左側和右側上交替排的JavaFX
這裏的設計我都取得了至今
我想在左右側交替行。
請誰能告訴我怎樣才能做到這一點。
我如何可以設置它。我試過listView.getStylesheets()。add(「list-view」);但它沒有工作 –
在[教程](http://docs.oracle.com/javafx/2/css_tutorial/jfxpub-css_tutorial.htm),節「創建樣式表」。例如。如果你有一個'app.css'你'Application'源身邊,那麼你可以撥打:''scene.getStylesheets()添加;'(的getClass()的getResource( 「app.css」)的toString()。) – DVarga
scene.getStylesheets()。add(「ChatStyle.css」); &listView.getStyleClass()。add(「list-view」);我試過但不爲我工作 –