A ColorInput creates a rectangular fill without creating a node.
Here it is applied to a rectangle. Note it does not fill the entire rectangle since the effect is 25 pixels high, compared to rectangle height of 50 px. The size of the rectangle is shown on the right.
package ex56;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.ColorInput;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Ex56 extends Application {
@Override
public void start(Stage stage) {
Group root = new Group();
ColorInput colInput = new ColorInput();
colInput.setX(100); colInput.setY(100);
colInput.setWidth(100); colInput.setHeight(25);
colInput.setPaint(Color.BLUE);
Rectangle rect1 = new Rectangle(100, 100, 100, 50);
rect1.setEffect(colInput);
Rectangle rect2 = new Rectangle(300, 100, 100, 50);
rect2.setFill(Color.BLUE);
root.getChildren().addAll(rect1, rect2);
Scene scene = new Scene(root, 500, 300, Color.LIGHTYELLOW);
stage.setTitle("Example 56. ColorInput");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
This is the output:
No comments:
Post a Comment