javafx - 如何在 JavaFX 的网格窗格中停止与其他列重叠的列中的内容?
问题描述
我在网格窗格中有一个动画,并且动画与网格窗格中的其他列重叠。
我试图通过介绍来阻止这种情况:
popUpWin.setHgrow(msg, Priority.NEVER);
我尝试在网格窗格中添加填充:
popUpWin.setHgap(8);
popUpWin.setVgap(6);
popUpWin.setPadding(new Insets(10, 20, 12, 20));
到目前为止我的代码:
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
public class VRAnimate extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
GridPane popUpWin = new GridPane();
Image imageComp = new Image("Loading VR-computer.png");
ImageView imageViewComp = new ImageView();
imageViewComp.setImage(imageComp);
imageViewComp.setFitWidth(200);
imageViewComp.setFitHeight(150);
Image imageVR = new Image("Loading VR-VR.png");
ImageView imageViewVR = new ImageView();
imageViewVR.setImage(imageVR);
imageViewVR.setFitWidth(241);
imageViewVR.setFitHeight(215);
Text msg = new Text("01001001 00100000 01101100 01101111 01110110 01100101 00100000"
+ "01001001 01101110 01110100 01100101 01110010 01100110 01100001 01100011 01100101"
+ "00100000 01000100 01100101 01110011 01101001 01100111 01101110 00101100 00100000"
+ "01001001 01101110 01110100 01100101 01110010 01100001 01100011 01110100 01101001"
+ "01101111 01101110 00100000 01100001 01101110 01100100 00100000 01000101 01111000"
+ "01110000 01100101 01110010 01101001 01100101 01101110 01100011 01100101");
msg.setTextOrigin(VPos.TOP);
msg.setFont(Font.font("Arial", FontWeight.NORMAL,40));
msg.setFill(Color.WHITE);
double msgWidth = 600;
KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), -1000);//new KeyValue(msg.translateXProperty(), 600);
KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);
KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), 600);//new KeyValue(msg.translateXProperty(), -1.0 * msgWidth);
KeyFrame endFrame = new KeyFrame(Duration.seconds(10), endKeyValue);
Timeline timeline = new Timeline(initFrame, endFrame);
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
popUpWin.getColumnConstraints().add(new ColumnConstraints(300));
popUpWin.getColumnConstraints().add(new ColumnConstraints(700));
popUpWin.getColumnConstraints().add(new ColumnConstraints(300));
popUpWin.addColumn(0,imageViewComp);
popUpWin.addColumn(1,msg);
popUpWin.addColumn(2,imageViewVR);
GridPane.setHalignment(imageViewComp, HPos.CENTER);
GridPane.setHalignment(imageViewVR, HPos.CENTER);
FadeTransition ft = new FadeTransition(Duration.millis(2500), imageViewVR);
ft.setFromValue(1.0);
ft.setToValue(0.2);
ft.setAutoReverse(true);
ft.setCycleCount(50);
ft.play();
Scene scene = new Scene(popUpWin, 1300, 215, Color.rgb(234,136,55));
primaryStage.setScene(scene);
primaryStage.show();
}
}
我期望作为网格窗格中第 1 列的文本消息不会将文本重叠到其他列上
解决方案
推荐阅读
- python - 在 Python 中使用 Tkinter 时文本未更改
- python - 从 pandas/dictionary 创建交互式层次结构图
- python - 热图显示每个单元格的两个变量
- c++ - 从头文件中删除 pimpl
- excel - 通过提供工作表名称和单元格地址返回表名称的公式
- sql - 有没有办法在 BigQuery 中保存的视图中使用脚本方法?
- bash - 从 docker entrypoint 命令获取退出代码
- python - 从 JSON 中提取特定密钥
- powershell - 寻找一种在powershell中将列添加到现有CSV的方法
- php - 如果行在 FPDF 中换行,则推送内容