I have trying to figure out how to use a CustomListCell
with a ListView
in JavaFX
but no luck, I have looked up and all I can find are incomplete tutorials and questions. Below is my CustomListCell
FXML
<AnchorPane id="AnchorPane" styleClass="backPane"
stylesheets="@../css/mainwindow.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox alignment="CENTER_LEFT" styleClass="backPane">
<children>
<HBox styleClass="card" HBox.hgrow="ALWAYS">
<children>
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/picture_placeholder.png" />
</image>
</ImageView>
<VBox HBox.hgrow="ALWAYS">
<children>
<Label fx:id="lbTitle" styleClass="fixture-title" stylesheets="@../css/mainwindow.css" text=" Livingston 19:45 Falkirk" />
<Label fx:id="lbDescription" styleClass="fixture-description" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin at turpis nisl. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vestibulum laoreet elementum velit. Curabitur tincidunt finibus malesuada. Aliquam dapibus semper scelerisque. Sed tristique tellus eget sem ornare cursus." />
</children></VBox>
</children>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</HBox>
</children>
</HBox>
</children>
</AnchorPane>
And my model
public class Ticket {
private long id;
private String imageUrl;
private String title;
private String description;
public Ticket(long id, String imageUrl, String title, String description) {
this.id = id;
this.imageUrl = imageUrl;
this.title = title;
this.description = description;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
And my incomplete CustomListCell
public class TicketCell <Ticket> extends ListCell<Ticket> {
private final TicketCellController ticketCellController = new TicketCellController();
private final Node view = ticketCellController.getView();
@Override
protected void updateItem(Ticket item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
ticketCellController.setTicket(item);
setGraphic(view);
}
}
}
And my controller
public class TicketCellController implements Initializable{
private static final String TAG = MainWindowController.class.getSimpleName();
private Logger logger;
private Ticket ticket;
@FXML
private Label lbTitle;
@FXML
private Label lbDescription;
@FXML
private AnchorPane anchorPane;
@Override
public void initialize(URL url, ResourceBundle rb) {
logger = Logger.getLogger(MainWindowController.class);
BasicConfigurator.configure();
}
Please not that ticketCellController.getView()
is not being found. Am lost at this point, I donnot know the right way of updating the imageview and labels on in my CustomListCell
FXML. Anyone to help or with a link to a tutorial I can follow, I will appreciate.