Custom palette in the ColorPicker

夙愿已清 提交于 2020-01-02 20:10:27

问题


I would like to change the color palette. The colors are by default have a transparency of 30%.

Is it possible to replace the color palette?


回答1:


Based on this solution, you can replace the color palette once you get the rectangles and their colors.

For instance, you can make brighter all the palette:

    @Override
public void start(Stage primaryStage) {
    ColorPicker picker = new ColorPicker();
    StackPane root = new StackPane(picker);
    Scene scene = new Scene(root, 500, 400);

    primaryStage.setScene(scene);
    primaryStage.show();
    picker.showingProperty().addListener((obs,b,b1)->{
        if(b1){
            PopupWindow popupWindow = getPopupWindow();
            Node popup = popupWindow.getScene().getRoot().getChildrenUnmodifiable().get(0);
            popup.lookupAll(".color-rect").stream()
                .forEach(rect->{
                    Color c = (Color)((Rectangle)rect).getFill();
                    // Replace with your custom color  
                    ((Rectangle)rect).setFill(c.brighter());
                });
        }
    });
}

private PopupWindow getPopupWindow() {
    @SuppressWarnings("deprecation") 
    final Iterator<Window> windows = Window.impl_getWindows();
    while (windows.hasNext()) {
        final Window window = windows.next();
        if (window instanceof PopupWindow) {
            return (PopupWindow)window;
        }
    }
    return null;
}



来源:https://stackoverflow.com/questions/29299707/custom-palette-in-the-colorpicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!