How to pass JavaFX variable into CSS style?


Tags: javafx,javafx-8,javafx-css

Problem :

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


Solution :

Try to put variable content value instead of its name:

ShortcutButton.setStyle("-fx-background-color: " + hex + ";");

    CSS Howto..

    how to remove element.style in css

    How long can a webpage be?

    Is there a CSS style guide for large existing projects. Or how could I optimize the css for a large project [closed]

    CSS isn't shown when HTML file is opened in Word

    How to edit css margin-top for a text in mobile version

    How to display text left side and icon on right side in html css?

    Show popout bubble above when no space available below

    Background color does not show up when scrolling to the right

    How to use Bootstrap style of BreadCrumb with my ASP.NET menu?

    how to trigger “onMouseOut” from click

    How To Left Align the Title Using CSS

    How to align multiple input using css

    How to separate html header and content with css and make the content scrollable

    How to reset jQuery toggled classes applied throughout the page? (AngularProject)

    Captions not showing correctly when using Anything Slider

    How Can I Hide *Only* the Button (Not Entire Element) for the Input Type File in a Django Form? [duplicate]

    how to make the navbar fixed to top

    How to detect redraw rate (fps) of a css animation?

    How to display element on screen but not at the top of the screen in html/css?

    How can I change this HAML format to normal CSS style?

    How to remove a specific class on the clicked control?

    How can I make the parent div draggable

    How to display two forms next to each other

    How to add custom css/js to just one page in WordPress?

    How to write CSS for parent DIV needing height dictated by child DIVs that are also anchored bottom?

    How to resize a chosen jquery dropdownlist on windows resize

    How do I write a CSS for mouse hover [duplicate]

    How to implement image sticker (ribbon) with css3

    How to change underline thickness of an a-tag without using border?

    how to remove some css attributes defined by bootstrap