我在网格窗格中有一个动画,并且该动画与网格窗格中的其他列重叠。
我试图通过引入以下内容来阻止这种情况:
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列的Text Msg不会将文本重叠到其他列上