Purpose: Create a round button with several text fonts.
Example: See RoundButtonWithMultipleFonts.java and RoundButtonWithMultipleFonts.css
RoundButtonWithMultipleFonts.java:
import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Control; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class RoundButtonWithMultipleFonts extends Application { public static void main(String... args) { launch(args); } @Override public void start(Stage stage) throws Exception { stage.setTitle("Button with multiple fonts?"); stage.setScene(new Scene(getRoot(), 400, 400)); stage.getScene().getStylesheets().addAll(getClass().getResource("RoundButtonWithMultipleFonts.css").toExternalForm()); stage.sizeToScene(); stage.show(); } private Parent getRoot() { Button button = new Button("");
RoundButtonWithMultipleFonts.css:
.button { -fx-border-width: 1px; -fx-border-color: #000000; -fx-border-radius: 45; -fx-background-color: linear-gradient(#ffffff 0%, #cccccc 100%); -fx-background-radius: 45; -fx-padding: 50 100; } .button:hover { -fx-background-color: linear-gradient(#ffffff 0%, coral 100%); } .label { -fx-padding: 10; -fx-background-color: cornflowerblue; } .header { -fx-font-size: 110%; -fx-font-weight: bold; -fx-translate-y: -20; } .footer { -fx-font-size: 80%; -fx-translate-y: 20; }
Execution Results:

Problem:
When the mouse scrolls over one of the corners of the buttons, the button goes into hovering, but the mouse is still outside the visible borders of the button, indicated by the button frame and background. (See Image.)
This example uses a stack panel, multiple labels, an event mechanism, and CSS crawl to create a button that contains text with multiple fonts.
Questions:
How can I indicate that a button should only go into hibernation if the mouse encounters the visual border of the buttons, as indicated in css with borders or background properties?
Is there an easier way to specify multiple fonts (with a common layout of text) for a button than what was done in this example? Ideally, I would just like to use a button with a nested Node as text. This would allow me to put everything that I would like into the text area of ββthe buttons, without the need for an event mechanism, StackPane and CSS snag.
source share