本文介绍了ColorPicker中的自定义调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改调色板。默认情况下,颜色的透明度为30%。
I would like to change the color palette. The colors are by default have a transparency of 30%.
是否可以替换调色板?
推荐答案
根据此,您可以在获得矩形及其颜色后替换调色板。
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;
}
这篇关于ColorPicker中的自定义调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!