ComboBox item disappearing when selected

John Hendrikx john.hendrikx at gmail.com
Sat Nov 8 22:12:11 UTC 2025


Hi,

I'm guessing you're setting the disappearing item as "Graphic", because
it is a Label and not a string.  However, you can only set a Node
(anywhere, including as graphic) in one part of the scene graph. 
Setting it somewhere else will cause it to be removed in the old
location (without warning unfortunately).

In this case, the Label is likely used as graphic in two places: once in
the list (as a cell), and once in the edit area (as another cell) of the
ComboBox when it was the last one selected.  This is causing the odd
disappearing artifact.

Best practice is to not use Nodes as items for a ComboBox.  Instead, use
a Record or some other type that the ListCell::updateItem will convert
to be shown in the way you want.

--John

On 08/11/2025 22:26, Cormac Redmond wrote:
> Hi,
>
> There is a bug whereby if you select a ComboBox item the item
> disappears / becomes invisible.
>
> This ComboBox consists of strings and a Label node and the Label node
> will disappear from the dropdown if it's selected (though, continue to
> take up space).
>
> I'm just picking a Label for example, it appears to happen with any
> Node that I've tried.
>
> bug_cb.gif
>
>
> Steps to reproduce (JFX 26, master branch). Note: I've kept the sample
> smallintentionally, but if you use a CellFactory (to call setText() or
> setGraphic() accordingly, as normal), the /same/ thing happens. In
> other words, the bug doesn't seem to be because of "mis-use" of the
> ComboBox by mixing types -- I think.
>
> public class ComboBoxDisappearingItemBug extends Application {
>     public static void main(String[] args) {
>         launch(args);
>     }
>
>     public void start(Stage stage) {
>         ComboBox<Object> cb = new ComboBox<>();
>         cb.getItems().addAll("Apple", "Banana", new Label("I will
> disappear"), "Carrot", "Lettuce");
>         cb.getSelectionModel().selectFirst();
>         stage.setScene(new Scene(cb, 200, 100));
>         stage.show();
>     }
> }
>
>
>
> Kind Regards,
> Cormac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20251108/8330fd64/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug_cb.gif
Type: image/gif
Size: 85745 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20251108/8330fd64/bug_cb-0001.gif>


More information about the openjfx-dev mailing list