JavaFXUI在旋转标签后冻结

JavaFXUI在旋转标签后冻结,java,javafx,Java,Javafx,在start(Stage primaryStage)之外的函数中对标签使用setRotate()后,旋转会起作用,但在标签上应用旋转后,UI会冻结 try { Platform.runLater(() -> textLabel.setRotate((new Random().nextInt(30 - (-30) + 1) + (-30))) ); } catch (Exception e1) { e1.printStackTrace(); } 我

在start(Stage primaryStage)之外的函数中对标签使用setRotate()后,旋转会起作用,但在标签上应用旋转后,UI会冻结

try {
    Platform.runLater(() -> 
        textLabel.setRotate((new Random().nextInt(30 - (-30) + 1) + (-30)))
    );
} catch (Exception e1) {
    e1.printStackTrace();
}
我需要更改什么才能使UI不会冻结

编辑:根据要求,下面是我代码中更详细的部分。基本上,用户可以单击一个按钮,然后文本应该旋转。它确实会旋转,但是JavaFXUI会完全冻结

public class Main extends Application {

    @FXML
    private TextArea TextArea1;
    @FXML
    private Button Button1;
    @FXML
    private ImageView BackgroundImgView;

    @FXML
    public void doSomethingAfterPressingButton1() {
        try {
            String userText = TextArea1.getText();
            if (userText == null || userText.isEmpty())
                TextArea1.setText("Please enter a text into this field");
            else {
                TextArea1.setText(userText);
                doRotate(userText);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void doRotate(String text) {
        try {
            if (Button1.getText().equals("Rotate")) {
                Button1.setText("New");
                textLabel.setText(text);

                String[] colorArray = { "#ffa500", "#ffd106", "#ffffc0", "#ffffa8", "#ffff00", "#ffffc4", "#ffffdd",
                        "#fddc68", "#fee911", "#f9ed37", "#fcfa85", "#fcf852", "#d7fdec", "#d7edec", "#d7ddec",
                        "#d7cdec", "#d7bdec", "#00ffec", "#ff0000", "#89ff00", "#fff400", "#e300ff", "#fc59a3",
                        "#87c830", "#ffd400", "#fe7e0f", "#8e3ccb", "#00f9ff", "#5ff4da", "#ffe441", "#f2f411",
                        "#b8ff75", "#ffc100", "#c356ea", "#8ff243", "#71aef2", "#ea5645", "#ff0000", "#1dff00",
                        "#ff8a00", "#fcff00", "#ffca31", "#00fff9", "#ffdb00", "#15ff00", "#ff3300", "#8900ff",
                        "#1322a6", "#e81111", "#5a36a3", "#106125", "#abd91f", "#f4f1af", "#f7f960", "#fff400",
                        "#e3ff00", "#a7a10a", "#ff5b5b", "#ffc75d", "#b8ff52", "#91f7ff", "#ff82d4", "#91aaff",
                        "#ff9e9e", "#ff80c5", "#7afbff", "#8aff9c", "#fff518", "#ffc100", "#55b6ff", "#76ff0c",
                        "#bd6fff", "#ff7272", "#ffca78", "#fdff58", "#99ff2d", "#31ffdc", "#9600ff", "#bd00ff",
                        "#ff00e7", "#ff008d", "#ff005a", "#e1e6f5", "#efefef", "#f3ffea", "#ffe9e9", "#ffd8f8",
                        "#ff0000", "#1dff00", "#ff8a00", "#fcff00", "#ffca31", "#ba1818", "#336927", "#a3ff00",
                        "#008080", "#9500d8", "#daf0aa", "#b5e37f", "#9fc360", "#ffec7b", "#ecd860",
                        "#ffffff" };
                textLabel.setTextFill(Color.web(colorArray[new Random().nextInt(colorArray.length)]));

                textLabel.setVisible(true);
                TextArea1.setVisible(false);
                addrandomBackgroundImg();
                BackgroundImgView.setVisible(true);

                Platform.runLater(() -> textLabel.setRotate((new Random().nextInt(30 - (-30) + 1) + (-30))));

            } else {
                Button1.setText("Rotate");
                textLabel.setVisible(false);
                TextArea1.setVisible(true);
                BackgroundImgView.setVisible(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我不确定问题的原因是什么,但您是否尝试过使用
Platform.runLater(new Runnable(){@Override public void run(){})
而不是
lambda
表达式?请发布一个显示问题的最小完整示例。创建一个演示问题的示例。这不是由你发布的代码引起的。@Yahida我试过这么做,但没有成功。无论如何谢谢你。另外,我只添加了一个最小的完整代码示例。