我有這個簡單的課程:
測驗.java:
import javafx.animation.FadeTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Test extends Application {
@Override
public void start(Stage stage) throws Exception {
Pane pane = new Pane();
Button testButton = new Button("Test");
testButton.setStyle("-fx-background-color: green;");
pane.getChildren().add(testButton);
pane.setStyle("-fx-background-color: red;");
FadeTransition transition = new FadeTransition(Duration.millis(5000), pane);
transition.setFromValue(1.0);
transition.setToValue(0.0);
transition.setCycleCount(Timeline.INDEFINITE);
transition.setAutoReverse(true);
transition.play();
Scene scene = new Scene(pane, 500, 500);
stage.setMinWidth(500);
stage.setMinHeight(500);
stage.setTitle("Test");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
}
它看起來像這樣:

然而,當它消失時,它變成了這樣:

如何使淡入淡出過渡只影響紅色背景而不影響綠色按鈕?
所以它看起來像這樣:

uj5u.com熱心網友回復:
使用堆疊窗格

您可以StackPane 作為 root 使用,也可以同時使用 :Pane和Button stackpane 的子項。Button 不受轉換的影響,因為它不再是 pane 的子項。
如果您需要不同節點的不同對齊,您可以使用 StackPane 類中的靜態方法setAligment,這需要一個子節點和位置作為引數
public class App extends Application {
@Override
public void start(Stage stage) throws Exception {
Pane pane = new Pane();
Button testButton = new Button("Test");
testButton.setStyle("-fx-background-color: green;");
StackPane stackPane = new StackPane(pane,testButton);
stackPane.setAlignment(Pos.TOP_LEFT);
pane.setStyle("-fx-background-color: red;");
FadeTransition transition = new FadeTransition(Duration.millis(5000), pane);
transition.setFromValue(1.0);
transition.setToValue(0.0);
transition.setCycleCount(Timeline.INDEFINITE);
transition.setAutoReverse(true);
transition.play();
Scene scene = new Scene(stackPane, 500, 500);
stage.setMinWidth(500);
stage.setMinHeight(500);
stage.setTitle("Test");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/491101.html
上一篇:如何有效地提取字串中的實體值
下一篇:org.apache.kafka.streams.errors.StreamsException:序列化程式(鍵:BytesSerializer/值:BytesSerializer)與實際鍵不兼容
