How to use Fx-Label of Java
This article mainly introduces "how to use Fx-Label of Java". In daily operation, I believe many people have doubts about how to use Fx-Label of Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Fx-Label of Java". Next, please follow the editor to study!
Effect.
Import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.scene.control.Label;import javafx.scene.input.MouseEvent;import javafx.scene.layout.HBox;import javafx.scene.text.Font;import javafx.stage.Stage;public class LabelSample1 extends Application {Label label3 = new Label ("A label that needs to be wrapped"); public static void main (String [] args) {launch (args) } @ Overridepublic void start (Stage stage) {Scene scene = new Scene (new Group ()); stage.setTitle ("Label Sample"); stage.setWidth (200,180); Label label2 = new Label ("Values"); label2.setFont (Font.font ("Cambria", 32)) / / rotation angle label2.setRotate (270,270); / / Vertical movement position label2.setTranslateY (50); / / whether to wrap label3.setWrapText (true) if the label width is exceeded; label3.setTranslateY (50); label3.setPrefWidth (100) / / Mouse arrival label3.setOnMouseEntered ((MouseEvent e)-> {/ / label3.setText ("); label3.setScaleX (1.5); label3.setScaleY (1.5) / / visible but invisible is no longer controlled by label3.setVisible (true) such as mouse and keyboard; System.out.println ("22222");}); label3.setOnMouseExited ((MouseEvent e)-> {label3.setScaleX (1); label3.setScaleY (1)) / / label3.setText ("A label that needs to be wrapped"); / / label3.setVisible (false); System.out.println ("111111");}); HBox hbox = new HBox (); hbox.setSpacing (10); hbox.getChildren () .add (label2) Hbox.getChildren () .add (label3); ((Group) scene.getRoot ()) .getChildren () .add (hbox); stage.setScene (scene); stage.show ();}} at this point, the study on "how to use Java's Fx-Label" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!