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

@Override
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" );
            pt.play();
        }
    } );

    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 );
    primaryStage.show();
}

with style.css like

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

    CSS Howto..

    How to make a correct mosaic with CSS?

    How would I change the code to work with a table instead of body? [closed]

    How to make hover use border-radius first-child

    how to create arrow between two background images in css

    jquery .show() hides immediately

    How to prevent CSS table row expanding to parent height

    How to make “transbox” full width

    How to create a simple Modal Dialog Box in JQuery?

    show the div inside that div next to it

    How to edit the element.style css?

    CSS - How to achieve a mixed effect of “float left” and “text-align: center”?

    css: how to center box div element directly in center?

    How to display 3 buttons on the same line in css

    Understanding how VS parses CSS in .ascx docs

    how to center a div in a td cell and a link inside of it ?both vertically and horizontally?

    How to get innerHTML of a node using scrapy Selector?

    show div border when link is clicked

    jQuery UI sortable: how to leave css values of changed items untouched?

    How can I get this toggled drop down menu to be open by default - rather than having to have someone click it to initialize it?

    CSS: how to enforce word wrap on an odd situation?

    How to display random parts of a page on refresh?

    how can I align text/image/links within a grid
    of the twitter bootstrap css?

    How to auto resize img group with browser change size?

    How to rotate an image on click and then rotate it back after another click? Using HTML, CSS and jQuery

    How to overlap auto-scaling images with an auto-scaling background

    How to reload CSS after ajax call

    How to add border inner side of image using CSS

    How can I make a div element float left after another float left while still filling the rest of the parent's width?

    How to make hover dynamic in CSS?

    Z-stacking CSS 3 Flex boxes : how to overlay DIVs that are flexbox items?