The label is only visible again if I scroll out then back in view.
Image 1) Before selection
Image 2) After selection.
However, the solution is literally in the API documentation (see below). But it implies a method override. How to approach this in B4J ? I don't mind using a workaround for this.
------------------------------------------------------------------------------------------
The recommended approach, rather than inserting Node instances into the items list, is to put the relevant information into the ComboBox, and then provide a custom cell factory. For example, rather than use the following code:
ComboBox<Rectangle> cmb = new ComboBox<>();
cmb.getItems().addAll(
new Rectangle(10, 10, Color.RED),
new Rectangle(10, 10, Color.GREEN),
new Rectangle(10, 10, Color.BLUE));}
You should do the following:
ComboBox<Color> cmb = new ComboBox<>();
cmb.getItems().addAll(
Color.RED,
Color.GREEN,
Color.BLUE);
cmb.setCellFactory(p -> {
return new ListCell<>() {
private final Rectangle rectangle;
{
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
rectangle = new Rectangle(10, 10);
}
@override protected void updateItem(Color item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
rectangle.setFill(item);
setGraphic(rectangle);
}
}
};
});
B4X:
Dim cbox as ComboBox
cbox.Initialize("")
For Each FontFamilyName As String In fx.GetAllFontFamilies
Dim font As Font = fx.CreateFont(FontFamilyName, 16, False, False)
Dim lbl As Label
lbl.Initialize("lbl")
lbl.Text = fontFamilyName
cbox.Items.Add(lbl)
Next
Image 1) Before selection
Image 2) After selection.
However, the solution is literally in the API documentation (see below). But it implies a method override. How to approach this in B4J ? I don't mind using a workaround for this.
------------------------------------------------------------------------------------------
The recommended approach, rather than inserting Node instances into the items list, is to put the relevant information into the ComboBox, and then provide a custom cell factory. For example, rather than use the following code:
ComboBox<Rectangle> cmb = new ComboBox<>();
cmb.getItems().addAll(
new Rectangle(10, 10, Color.RED),
new Rectangle(10, 10, Color.GREEN),
new Rectangle(10, 10, Color.BLUE));}
You should do the following:
ComboBox<Color> cmb = new ComboBox<>();
cmb.getItems().addAll(
Color.RED,
Color.GREEN,
Color.BLUE);
cmb.setCellFactory(p -> {
return new ListCell<>() {
private final Rectangle rectangle;
{
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
rectangle = new Rectangle(10, 10);
}
@override protected void updateItem(Color item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
rectangle.setFill(item);
setGraphic(rectangle);
}
}
};
});