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

16 進変数に必要な色があります。

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