JavaFX: How can I best place a Label centered in a Shape? -
Assume that I have a size on the screen for example:
circle circle = New circle (x, y, radius); Circle.setFill (Color.YELLOW); . Root.getChildren () (cycle) add; I would like to create a label "over" in the circle, as if the label is centered in the circle, the forest size is maximum to fit inside the circle, etc.
I can see how this can be accomplished through binding, but it seems unnecessarily complex that if the condition / size of these things never change during the runtime.
Thank you in advance for your help! I am very new to JavaFX and have no experience in programming in the first place, so I apologize if I should find out through my research.
Use the text located above the shape to automatically center.
import javafx.application.Application ; Import javafx.geometry.Insets; Import javafx.scene *; Import javafx.scene.layout.StackPane; Import javafx.scene.paint.color; Import javafx.scene.shape.Circle; Import javafx.scene.text. *; Import javafx.stage.Stage; // Java 8 code expands the public class circular application {public static zero main (string [] args) Exception {throws (launch); } @ Override throws the exception of the public sound start (final stage stage) {text text = createtext ("Xzi"); Circle circle = eric (text); StackPan layout = new StackPan (); Layout .get child () AddAll (Circle, Text); Layout.setpadding (new insets (20)); Stage.setScene (new view (layout)); stage show(); } Create private lessonsTest (string string) {text text = new text (string); text.setBoundsType (TextBoundsType.VISUAL); Text.setStyle ("-fx-font-family: \" times new roman \ ";" + "-fx-font-style: italic;" + -fx-font-size: 48px; "); return text;} Personal Circle Scope (Text Lessons) {Circle Circle = New Circle (); circle.setFill (Color.ORCHID); Last Double Padding = 10; circle.setRadius (getWidth (text) / 2+ padding); Return cycle;} Personal Double getWidth (text view) {new view (new group (text)); text.applyCss (); return text .get layoutbound (). GetWidth ();}} Related -
Respond to the related question separately discusses the type of range (e.g. Ima), if you need it.
Comments
Post a Comment