JavaFX有没有任何颜色渐变编辑器控件?

时间:2016-04-08 14:37:10

标签: javafx

对于可以将Noise Function(-1到1值)映射到Colors的编辑器,我需要一些Control来定义Color Gradient,所以像 值 - 0是黑色的 - 0.3是黄色 - 0.8是红色的 - 1是白色的 所以整个渐变从黑到白,这是可编辑的, 有什么类似内置于JavaFX或我必须编写自己的控件吗?

基本上像这样:

enter image description here

提前致谢

2 个答案:

答案 0 :(得分:3)

实际上,Scene Builder有一个强大的渐变编辑器,允许插入多个停靠点:

Scene Builder

该控件名为PaintPicker,它是可以从here下载的Scene Builder Kit的一部分。

拥有jar后,您可以使用该组件。

这是一个简短的片段,展示了如何轻松地将其添加到您的场景中:

@Override
public void start(Stage primaryStage) {
    VBox root = new VBox();
    root.setAlignment(Pos.CENTER);
    root.setPadding(new Insets(10));

    PaintPickerController controller;
    final FXMLLoader loader = new FXMLLoader();
    loader.setLocation(PaintPicker.class.getResource("PaintPicker.fxml")); 

    try {
        final VBox picker = loader.load();
        controller = loader.getController();
        controller.paintProperty().addListener((obs, ov, nv) -> System.out.println("Paint: " + nv));
        root.getChildren().add(picker);
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }

    Scene scene = new Scene(root, 320, 600);

    primaryStage.setTitle("SceneBuilder PaintPicker");
    primaryStage.setScene(scene);
    primaryStage.show();
}

Paint Picker

使用监听器,您将立即获得渐变:

Paint: linear-gradient(from 60.096% 38.461% to 47.115% 45.192%, 
    reflect, 0xda7777ff 0.0%, 0x226621ff 28.667%, 0xf2ff1cff 49.333%, 
    0xff1c5fff 73.0%, 0xffffffff 100.0%)

答案 1 :(得分:0)

我认为您正在寻找ColorPicker

enter image description here

有关如何使用它的更多信息位于JavaFX tutorials page

相关问题