How to time the effect of a css look in javafx?

Tags: css,javafx

Problem :

Is it possible to give timing for the effects described in CSS?

So what I would like to have is, that if you push a button, then the change in its look lasts a bit longer, even a bit after the release.

So I would imagine some kind of command in the .button:pressed{} section, that makes this possible.

Or if its only possible in the java code, that's good too! Do you have an idea? Thanks!

So for example:

.button:hover:pressed {
-fx-background-color: #A6C3F1;
-fx-background-radius: 30;
-fx-text-fill: black;
//pseudo: -fx-pressed-lasts: 300 (milisec);

So if you klick on the button, while you are holding the click, the button is gonna have this color. I would like to have this color 300 milisec long even after releasing the mouseclick. And then it would change back to .button:hover{ - whatever -}

Solution :

Imo it is not possible within css. In Java code you can use

public void start( Stage primaryStage )
    final Button btn = new Button( "Say 'Hello World'" );
    final PauseTransition pt = new PauseTransition( Duration.millis( 3000 ) );
    pt.setOnFinished( ( ActionEvent event ) ->
        btn.getStyleClass().remove( "my-button-pressed" );
    } );

    btn.setOnMousePressed( ( MouseEvent event ) ->
        if ( pt.getStatus() != Animation.Status.RUNNING )
            btn.getStyleClass().add( "my-button-pressed" );
    } );

    StackPane root = new StackPane();
    root.getChildren().add( btn );

    Scene scene = new Scene( root, 300, 250 );
    scene.getStylesheets().add( this.getClass().getResource( "style.css" ).toExternalForm() );
    primaryStage.setScene( scene );;

with style.css like

.my-button-pressed {
    -fx-font: 16px "Serif";
    -fx-padding: 10;
    -fx-background-color: #CCFF99;

    CSS Howto..

    How to disable mask on selected image in the f/ckeditor in webkit, opera browsers?

    css button with arrow… how to move arrow

    CSS - How to apply box-shadow to a image rounded

    How to vertically aligned to middle with bootstrap?

    How to make vertical menu with emenu extension in Yii?

    How to keep CSS from render-blocking my website?

    3x3 CSS grid: how to make center div the only one with a fixed height/width?

    How to add js and css files in Core?

    How to change CSS display property using an anchor tag?

    How to align Facebook, Twitter, Google+ and LinkedIn buttons on the right?

    CSS Positioning: How to make 2 overlapping divs and then 1 more div to the right of the overlapping divs

    How to move up an inner box and keep outer box in place with CSS?

    My sidebar is going over the footer. How can I sort this out?

    How to use SVG Sprite Sheet as CSS background-image while maintaining aspect ratio and scalability

    What is this HTML notation and how can I use it myself?

    How to apply CSS class to a split string

    How to change css of element using jquery

    CSS: how to get two floating divs inside another div

    How to put text in the center of box while using border-box in CSS?

    How to make a resizable menu centered on the middle?

    How to remove blue border around the button in Firefox?

    How to use CSS Rotate() in TH Table Tags

    How can i execute two effects on .mousenter THIS?

    How can one select a parent element several levels above the child element utilizing the 'hover' selector and ':has()'?

    How To Outline a PNG (Transparent) image with CSS?

    How to transition a CSS class between two separate additional classes?

    How can I create a color with values for green, blue, orange, and gold only?

    MVC How make a logout button

    How to define a good convention for css?

    How can I make it so the first element in a DIV has a different CSS to others?