In this tutorial session, we will learn the following things about JavaFX UI control – Button.
We are going to discuss on following points in detail, also we will learn how to write code for this.
1) How to set the icon image on the button?
2) Handling button click action? (with lambda expression and traditional FXML way)
3) Applying effects on the button.
-Adding the shadow when the mouse cursor is on
-Removing the shadow when the mouse cursor is off
4) Styling button with CSS.
Image image = new Image(getClass().getResourceAsStream(“likeImage.png”));
button1.setGraphic(new ImageView(image));
//do some action
label2.setText( “Hello Cool IT Help!” );
});
-Adding the shadow when the mouse cursor is on
-Removing the shadow when the mouse cursor is off
DropShadow shadow = new DropShadow();
//Adding the shadow when the mouse cursor is on
button2.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
button2.setEffect(shadow);
});
//Removing the shadow when the mouse cursor is off
button2.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
button2.setEffect(null);
});
4) Styling button with CSS.
For complete clarification and a detailed understanding of points 3 and point please watch my Video Tutorial session that I have posted on YouTube. Please click to watch the below video for a better understanding of each concept.