I have a choice-box. In my choice-box there is a list of colors to be selected by the user through the interface. Every time the user selects a color, the background of that same choice-box is the same color that the user selected. By default, the font color of the items in the choice-box is white, but among the options the user chooses, there is a white color ... so when he selects "White", the bottom of the choice box also turns white ... and as the default font is white, you know ... everything is white, "without text".
Here's how:
IntheStyleSheetfile,Ihavethefollowing:
.choice-box{-fx-background-color:black;-fx-mark-color:#950005;-fx-border:1px;}.choice-box>.label{-fx-text-fill:white;}
Upthere,asyoucansee,thefontcolorofthechoice-boxlistitemissetbydefaulttowhiteinthesecondCSSclass,thatis,inthe"label" subclass, within ".choice- box. "
When the guy selects a color item from the menu, the following action is performed on the choice-box's "OnAction" (after doing all the blablabla color checking):
choiceBox.setStyle("-fx-background-color: " + selectedColor + ";");
So far so good, the choice-box changes everything fillet color, but I want to put the following condition, to avoid the white font on a light / white background:
if(selectedColor.equalsIgnoreCase(BRANCO) ||
selectedColor.equalsIgnoreCase(AMARELO) ||
selectedColor.equalsIgnoreCase(CINZA) ||
selectedColor.equalsIgnoreCase(PRATA))
{
//ação para fazer a cor da fonte do item selecionado no menu ser preta quando a cor selecionada pelo usuário for branca, amarela, cinza ou prata
}
But I'm not able to access, by java, this subclass ".label" that is inside the choice-box. And you can not create a @FXML Label meuLabel
referencing this text. I would have to do this if what I wanted to change was the Label that stands above each menu, saying what it is. The idea would be to do something like this:
meuCoiceBox.getValue().setStyle("-fx-text-fill: black;");
or one
meuChoiceBox.getSelectionModel().getSelectedItem().setStyle("-fx-text-fill: black;");
... to change the text color of this item with a clear background.