-2

I want to change a specific pane color by using combo box. Whenever I select a color, grey for example, It changes the color of the Pane. I tried this code but it didn't do anything.

    **@FXML
    private void Select(ActionEvent event) {
        
        String myColor = ColorBox.getValue();
        
        if (myColor.equalsIgnoreCase("blue")){
            Pane.setStyle(myColor);
        } else if(myColor.equalsIgnoreCase("white")){
            Pane.setStyle("fx-background-color: white");
        } else if(myColor.equalsIgnoreCase("grey")){
            Pane.setStyle("fx-background-color: grey");
        }**
        
        
    }
    
}
Ammar
  • 1
  • 1
    It is good you found a solution to your problem. I suggest you Google for JavaFX naming conventions and use them also in future posts which request debugging assistance such as this is best to provide an [mcve]. – jewelsea Sep 18 '21 at 22:26
  • 1
    Also consider [`ColorPicker`](https://openjfx.io/javadoc/16/javafx.controls/javafx/scene/control/ColorPicker.html), a subclass of `ComboBoxBase`, seen [here](https://stackoverflow.com/search?tab=votes&q=%5bjavafx%5d%20ColorPicker). – trashgod Sep 18 '21 at 22:29
  • 1
    Similar [background random color changes](https://stackoverflow.com/questions/69021055/javafx-frame-background-random-color-changes/69038295#69038295), – jewelsea Sep 18 '21 at 22:31
  • 2
    It should be “-fx-background-color: white;” not “fx-background-color: white” – Miss Chanandler Bong Sep 19 '21 at 11:52

1 Answers1

-1

I solved it:

@FXML private void Select(ActionEvent event) {

    String myColor = ColorBox.getValue();

    if (myColor.equalsIgnoreCase("white")){
        Pane.setBackground(new Background(new BackgroundFill(Color.WHITE,null,null)));
Ammar
  • 1