📜  JavaFX ColorInput

📅  最后修改于: 2020-10-14 01:26:44             🧑  作者: Mango

JavaFX ColorInput

ColorInput产生类似于彩色Rectangle的输出。它不显示节点,而是显示矩形框。它主要作为输入传递给其他效果。类javafx.scene.effect.ColorInput表示ColorInput效果。此类的对象作为其他效果的输入传递。

物产

下表中描述了类javafx.scene.effect.ColorInput的属性及其设置方法。

Property Description Setter Methods
height It is of double type. It represents the height of the region that is to be filled. setHeight(double value)
paint It represents the paint with which the region is to be filled. setPaint(Paint value)
width It is of double type. It represents the width of the region that is to be filled. setWidth(double value)
x It represents the X coordinate of the top left corner of region. setX(double value)
y It represents the Y coordinate of the top left corner of the region. setY(double value)

建设者

该类包含两个构造函数。

  • public ColorInput():使用默认参数创建ColorInput的新实例。
  • public ColorInput(double x,double y,double width,double height,Paint paint):使用指定的参数创建ColorInput的新实例。

例:

下面的示例说明ColorInput效果的工作。

package application;
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 ColorInputExample extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
ColorInput color = new ColorInput();
color.setPaint(Color.RED);
color.setHeight(100);
color.setWidth(100);
color.setX(140);
color.setY(90);
Rectangle rect = new Rectangle();
rect.setEffect(color);
Group root = new Group();
Scene scene = new Scene(root,400,300);
root.getChildren().add(rect);
primaryStage.setScene(scene);
primaryStage.setTitle("ColorInput Example");
primaryStage.show();
}
}