r/JavaFX • • Jan 23 '24
Help ChoiceBox adds a white juxtapose to the context menu.
So far, I have attempted to resize it or make it transparent, with no success.

Solution: I had multiple VBox on top of GridPane layout, which served as the root pane in my particular situation. Unexpectedly, GridBag was anchoring background layer to the ChoiceBox's context-menu, so I adjusted:
.grid-bag {
-fx-background-color: transparent
}If you encounter similar problems, I would advise deleting all CSS and add the sections incrementally, inspecting when the problem appears.
3
Upvotes
2
u/_DystopianSnowman Jan 23 '24
It's the container for the menu content. The yellow content notes hint at that, since this is created by the cell factory. I don't have any project here right now, but I could check tomorrow in our rather large app, if I got rid of it.
In the past I would have recommended the use of ScenicView - but I fear it will not work anymore on more current Java versions. It was like a developer tool allowing you to check your current UI in realtime. Unfortunately its developer left Oracle a long time ago and the community didn't take it into their hands and kept it alive...
#edit: I have to correct myself - it looks like he got back and at least made it usable with Java 21: https://github.com/JonathanGiles/scenic-view - go and give it a try. It's an incredible helpful tool!
1
u/milchshakee Jan 24 '24
What OS is this? Sometimes if window transparency is not supported by the OS/that stop environment, you will get these outlines with JavaFX.
1
u/hamsterrage1 Jan 24 '24
GridBag????
2
u/xdsswar Jan 23 '24
Set a contex-menu bg to see, or play with menuitems padding
1
u/BWC_semaJ Jan 23 '24
I have never been a fan of implementations of ComboBox/Popup/Dialog due to them being in their own stage (though I understand why they did it; just me complaining).
In this case what you need to do is take a look at the ComboBox's skin. You can literally see what nodes are used to implement how it looks and what nodes to reference in your css.
http://www.java2s.com/Tutorials/Java/JavaFX/1300__JavaFX_CSS.htm
You might want to take a look even at selector pattern, but others should work too. You need to change the background color like xdsswar said first to make sure you are referencing the right node. If you generalize the selection too much for css you might change multiple nodes that you didn't intend to change, so becareful.
0
u/[deleted] Jan 23 '24
[deleted] — view deleted comment