gpt4 book ai didi

java - 在标签上使用 FadeTransition 会导致标签在过渡开始时显示不同

转载 作者:行者123 更新时间:2023-11-30 07:58:35 25 4
gpt4 key购买 nike

我的项目需要一个Label或一个Text。我需要标签以便可以使用省略号。但问题是,当我尝试使用 FadeTransition 并播放它时,标签在开始时会稍微变暗。这是一些演示代码:

package com.neonorb.test;

import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Duration;

import java.io.IOException;

/**
* Created by chris on 7/20/15.
*/
public class Test extends Application {
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws IOException {
Label label = new Label("hello");
//Text label = new Text("hello);//Using Text instead of Label does not cause the weird behavior
FadeTransition fadeTransition = new FadeTransition(Duration.seconds(3), label);
fadeTransition.setFromValue(1.0);
fadeTransition.setToValue(0.0);
fadeTransition.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
label.setOpacity(1.0);
}
});
Button button = new Button("play");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
fadeTransition.play();
}
});
BorderPane borderPane = new BorderPane();
borderPane.setCenter(label);
borderPane.setBottom(button);
primaryStage.setScene(new Scene(borderPane));
primaryStage.show();
}
}

所以我要么需要解决这个问题,要么需要一种在Text中使用省略号的方法。有什么想法吗?

最佳答案

最初将标签的不透明度设置为 0.99:

label.setOpacity(0.99);

也以同样的方式更改setOnFinished方法内的代码。然后,将淡入淡出过渡的起始值设置为0.99:

fadeTransition.setFromValue(0.99);

我知道这不是您正在寻找的解决方案,但该解决方案可以防止标签在开始时突然变暗。这是因为标签实际上以较暗的状态开始。

关于java - 在标签上使用 FadeTransition 会导致标签在过渡开始时显示不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32275118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com