0

I need that when I press a button, the button color changes, Im making the interface in scene builder and style it with fx css. I tried:

.botones:hover { 
    -fx-background-color: red;
}

.botones:pressed {
    -fx-background-color: blue;
}

.botones { 
    -fx-background-color:  #262626;
}

The hover works fine, but when i press the button, it turns blue for a second and then changes to its original color and i want it to stay blue.

Maybe i could use a toggle button instead, but im using jfoenix buttons because they have some cool effects.

JAram
  • 3
  • 7

1 Answers1

0

You're right that the ToggleButton in JFoenix is more of a switch:

JFXToggleButton

However, you can use a lesser-known control in JFoenix called JFXToggleNode.

JFXToggleNode Animation

Just put a label inside of it. (Don't forget to include the import statements.)

<?import com.jfoenix.controls.JFXToggleNode?>
<?import javafx.scene.control.Label?>

...

<JFXToggleNode>
    <Label text="Boton Azul" />
</JFXToggleNode>

and add this rule to your stylesheet:

.jfx-toggle-node {
    /* This is the color once toggled on. */
    -jfx-toggle-color: deepskyblue;
}

Note that SceneBuilder doesn't support non-standard controls very well, yet, so though you can't drag and drop it, you can add it manually to the FXML file just fine.

Brad Turek
  • 2,472
  • 3
  • 30
  • 56
  • Okay so i tried adding the button throught the fxml file, but what happens is that the button is always blue, i click on it and it is still blue, but thanks anyway! – JAram Apr 12 '18 at 19:28
  • I got you covered, @JAram. See the edits I've made. The `-jfx-toggle-color` is what you're looking for. – Brad Turek Apr 12 '18 at 19:35
  • @JAram, I've added a picture of the final product. – Brad Turek Apr 12 '18 at 19:44
  • Sorry i wasnt able to answer yesterday, however i tried it now, i added the toggle node throught FXML file and then i added the style in the css file, but for some reason its not working. – JAram Apr 13 '18 at 15:27
  • If you want to update your question with what you've got now, I might be able to help. – Brad Turek Apr 13 '18 at 15:47
  • Hey i just solved it!, what i did was:. fx-toggle-node { -fx-background-color: #262626; -fx-selected-color: blue } And it works perfectly! – JAram Apr 13 '18 at 16:07
  • You can surround your code with backticks there in the comments if you'd like to format it. The backtick key is the one right under `Esc` – Brad Turek Apr 13 '18 at 16:09
  • Now i need to make that a toggle node gets unselected when i select another node. But thats a different story ^^ – JAram Apr 13 '18 at 16:15