0

我想采用选定的颜色并更改按钮的背景颜色。

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;");
    }
4

2 回答 2

2

尝试放置变量内容值而不是其名称:

ShortcutButton.setStyle("-fx-background-color: " + hex + ";");
于 2015-06-08T09:58:17.700 回答
0

你在你的十六进制变量中有你想要的颜色。

if (!buttonColor.getStyle().trim().contains("-fx-background-color:" +hex)){   
    buttonColor.setStyle("-fx-background-color: " + hex + ";");
}
于 2015-06-08T13:29:17.527 回答