0

I want to take selected color and change background color of button.

private void  handleItemBackAction(ActionEvent eve)
{
          System.out.println("You clicked Set Background Color of Item!");     

        java.awt.Color color=JColorChooser.showDialog(null,"Select a color",java.awt.Color.CYAN);

        String hex = Integer.toHexString(color.getRGB() & 0xffffff);

        hex="#"+hex;
        Text.setText(hex);
        ShortcutButton.setStyle("-fx-background-color: hex;");
    }

2 Answers 2

2

Try to put variable content value instead of its name:

ShortcutButton.setStyle("-fx-background-color: " + hex + ";");
Sign up to request clarification or add additional context in comments.

Comments

0

You have the color you want in your hex variable.

if (!buttonColor.getStyle().trim().contains("-fx-background-color:" +hex)){   
    buttonColor.setStyle("-fx-background-color: " + hex + ";");
}

2 Comments

What if there is a style "-fx-border-color: hex;"?
you're right - either check for the whole property or skip this check altogether.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.