Reputation: 763
For an editor that can map a Noise Function (-1 to 1 values) to Colors I need some Control that lets me define a Color Gradient, so something like Value - 0 is black - 0.3 is yellow - 0.8 is red - 1 is white so the whole gradient goes from black to white and thats editable, is there anything like that built into JavaFX or do I have to write my own Control?
Basically smth like this:
Thanks in advance
Upvotes: 2
Views: 1493
Reputation: 45456
Actually, Scene Builder has a powerful gradient editor that allows inserting multiple stops:
The control is called PaintPicker
, and it is part of the Scene Builder Kit that you can download from here.
Once you have the jar, you can use the component.
This is a short snippet to show how to easily add it to your scene:
@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();
}
With the listener, you will get immediately the gradient:
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%)
Upvotes: 3
Reputation: 36742
I think you are looking for a ColorPicker.
More information on how to use it is on JavaFX tutorials page.
Upvotes: 0