Reputation: 27
I'm currently using JavaFX ColorPicker
to select colors in my application. The ones outside the TableView
work as expected, but I've run into an issue with the ones contained in the TableView
.
I'm currently using the solution found at Michael Simons's site to implement custom controls in a TableCell
. It works fine... until you open the Custom Color
dialog of the Color Picker. At this point, any interaction with the custom color dialog box closes and commits the edit, meaning you're unable to, as an example, key in an RGB code for specific color usage.
How do I keep this open until the custom color value is committed from this dialog?
Upvotes: 2
Views: 1289
Reputation: 27
Found a solution; hopefully it can help someone else searching:
The original solution used a change listener to commit the edited table cell:
this.colorPicker.valueProperty().addListener((observable, oldValue, newValue) -> {
if(isEditing()) {
commitEdit(newValue);
}
});
However, the ColorPicker
custom color window continuously updates the value as you drag the sliders or target around. As a result, the first time you'd click, the listener would fire and you'd end up out of the dialog.
Changing this to an event listener against the isHiding
event fixes this problem. The ColorPicker
hides when you select a preset color or when you click [Save] or [Use] in the custom color window. Replace the above snippet with this, and you're good to go!
this.colorPicker.setOnHiding(event -> {
if (isEditing()) {
commitEdit(this.colorPicker.getValue());
}
});
Upvotes: 1