HEJ彼得,
我這樣做是前一段時間是這樣的:
package de.professional_webworkx.blog.colorgradient;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
*
* @author ottp
*/
public class ColorGradient extends Application {
@Override
public void start(Stage primaryStage) {
final Pane pane = new BorderPane();
pane.setPrefWidth(300);
pane.setPrefHeight(200);
pane.setStyle("-fx-background-color: linear-gradient(from 25% 25% to 100% 100%, #dc143c, #661a33)");
final ColorPicker picker = new ColorPicker();
picker.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
Color value = picker.getValue();
String colorString = value.toString();
String substring = colorString.substring(2, colorString.length()-2);
pane.setStyle("-fx-background-color: linear-gradient(from 25% 25% to 100% 100%, #" + substring + ", #661a33)");
}
});
VBox vBox = new VBox();
vBox.getChildren().add(pane);
vBox.getChildren().add(picker);
Scene scene = new Scene(vBox);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
把它作爲一個起點,自己的解決方案.. 它只改變第一顏色值。
Patrick