javafx 8 create images on button on hover using css -
i'm making mario themed application, , buttons have effect when user hovers on his/her mouse, mushroom (image) appears next text of button, , disappears when mouse moves away.i'm trying using css.
how can 1 this?
use hover pseudoclasses.
.button:hover{ -fx-graphic: url('your_path_to_image'); }
complete example
import javafx.application.application; import javafx.geometry.pos; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.layout.hbox; import javafx.stage.stage; public class main extends application { public void start(stage primarystage) { button button = new button("click"); hbox container = new hbox(button); container.setalignment(pos.center); scene scene = new scene(container, 200, 200); scene.getstylesheets().add(getclass().getresource("/style.css").toexternalform()); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } }
style.css
.button:hover{ -fx-graphic: url('http://files.softicons.com/download/game-icons/super-mario-icons-by-sandro-pereira/png/16/mushroom%20-%201up.png'); }
image
on hover
Comments
Post a Comment