第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

刪除節(jié)點(diǎn)時(shí) UI 不更新

刪除節(jié)點(diǎn)時(shí) UI 不更新

蕪湖不蕪 2023-03-09 10:47:46
我試圖從我的窗格中逐個(gè)刪除所有節(jié)點(diǎn),這樣我就可以看到每一行都被刪除了。為此,我創(chuàng)建了一個(gè)新線程并使用了任務(wù)類并將方法 delWalls() 包裝在平臺(tái)中。運(yùn)行后()。然后我使用 Thread.sleep 認(rèn)為它會(huì)減慢循環(huán)速度所以我可以看到 UI 在每一行被刪除時(shí)更新但是會(huì)發(fā)生什么情況是整個(gè) UI 凍結(jié)然后在循環(huán)完成后所有節(jié)點(diǎn)都消失了?有沒(méi)有辦法解決這個(gè)......謝謝*所有節(jié)點(diǎn)都是線順便說(shuō)一句 //loop calls delWalls() 1458 times to delete all 1458 nodes sequentailly    Task task = new Task<Void>() {        @Override        public Void call() {            Platform.runLater(() -> {                try {                    for (int i = 0; i <= 1458 - 1; i++) {                        Thread.sleep(2);                        delWalls();                    }                } catch (InterruptedException e) {                    e.printStackTrace();                }            });            return null;        }    };    new Thread(task).start();    }//delWalls方法每調(diào)用一次刪除一個(gè)節(jié)點(diǎn)。  public void delWalls() throws InterruptedException {    pane.getChildren().remove(0); }
查看完整描述

1 回答

?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊

您需要使用 Timeline 才能獲得所需的效果。以下是如何完成的快速示例演示。單擊“添加”依次添加節(jié)點(diǎn),添加完所有 10 個(gè)節(jié)點(diǎn)后,單擊“刪除”將它們一一刪除。


import javafx.animation.KeyFrame;

import javafx.animation.Timeline;

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.layout.FlowPane;

import javafx.scene.layout.StackPane;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

import javafx.util.Duration;


public class RemoveNodes_Demo extends Application {

    @Override

    public void start(Stage stage) throws Exception {

        FlowPane pane = new FlowPane();

        pane.setVgap(10);

        pane.setHgap(10);


        Button button1 = new Button("Add Nodes");

        button1.setOnAction(e->{

            Timeline timeline = new Timeline(new KeyFrame(Duration.millis(400), x -> {

                StackPane sp = new StackPane();

                sp.setMinSize(100,100);

                sp.setStyle("-fx-background-color:black,red;-fx-background-insets:0,2;");

                pane.getChildren().add(sp);

            }));

            timeline.setCycleCount(10);

            timeline.play();

        });


        Button button2 = new Button("Remove Nodes");

        button2.setOnAction(e->{

            if(!pane.getChildren().isEmpty()){

                int count = pane.getChildren().size();

                Timeline timeline = new Timeline(new KeyFrame(Duration.millis(400), x -> {

                   if(!pane.getChildren().isEmpty()){ 

                      pane.getChildren().remove(0);

                   }

                }));

                timeline.setCycleCount(count);

                timeline.play();

            }

        });

        VBox root = new VBox(button1, button2,pane);

        root.setSpacing(10);

        Scene sc = new Scene(root, 600, 600);

        stage.setScene(sc);

        stage.show();

    }


    public static void main(String... a) {

        Application.launch(a);

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-03-09
  • 1 回答
  • 0 關(guān)注
  • 99 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)