效果
#### 代码
代码语言:javascript复制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);
}
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle("Label Sample");
stage.setWidth(200);
stage.setHeight(180);
Label label2 = new Label("Values");
label2.setFont(Font.font("Cambria", 32));
//旋转的角度
label2.setRotate(270);
//垂直移动位置
label2.setTranslateY(50);
// 超过了标签宽度,是否换行
label3.setWrapText(true);
label3.setTranslateY(50);
label3.setPrefWidth(100);
//鼠标到来
label3.setOnMouseEntered((MouseEvent e) -> {
// label3.setText("");
label3.setScaleX(1.5);
label3.setScaleY(1.5);
// 可见的 一但不可见则不再受控于鼠标键盘等
label3.setVisible(true);
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();
}
}