如何使用JavaFX创建ColorPicker?
拾色器为您提供标准的调色板,您可以选择所需的颜色。您可以通过实例化javafx.scene.control.ColorPicker类来创建颜色选择器。
示例
以下示例演示了ColorPicker的创建。
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class ColorPickerExample extends Application {
public void start(Stage stage) {
//Setting the label
Label label = new Label("Select Desired Color:");
Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
label.setFont(font);
//Creating a Color picker
ColorPicker picker = new ColorPicker();
//Creating a hbox to hold the pagination
HBox hbox = new HBox();
hbox.setSpacing(20);
hbox.setPadding(new Insets(25, 50, 50, 60));
hbox.getChildren().addAll(label, picker);
//Setting the stage
Group root = new Group(hbox);
Scene scene = new Scene(root, 595, 300, Color.BEIGE);
stage.setTitle("Color Picker");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短