ComboBox item disappearing when selected

Cormac Redmond credmond at certak.com
Sun Nov 9 00:26:20 UTC 2025


Hi,

Ah, of course, I should have realized that myself.

It would be nice if there was a warning or a property developers can set to
prevent that, for example, to check and throw an error if a node is used
twice.

Thanks for pointing it out, and apologies for reporting a non-issue.

(P.S. I sent another email just before this that I don't think falls into
the same user-error category!)



Kind regards,
Cormac

On Sat, 8 Nov 2025 at 23:08, John Hendrikx <john.hendrikx at gmail.com> wrote:

> 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.
>
> [image: bug_cb.gif]
>
>
> Steps to reproduce (JFX 26, master branch). Note: I've kept the sample
> small intentionally, 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/20251109/f81badf5/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/20251109/f81badf5/bug_cb-0001.gif>


More information about the openjfx-dev mailing list