lundi 29 août 2016

JavaFX8 CheckBoxTreeItem disable antialiasing in popup

In order for the end-user to constrain a search to some columns of the main TableView, I needed a treeview with checkboxes. I decided to embed this TreeView in a popup, showing on click on a custom button.

I have created the following class, inspired from the question: Java FX8 TreeView in a table cell

public class CustomTreeMenuButton extends MenuButton {
    private PopupControl popup = new PopupControl();
    private TreeView<? extends Object> tree;
    private CustomTreeMenuButton me = this;

    public void setTree(TreeView<? extends Object> tree){
        this.tree=tree;
    }

    public CustomTreeMenuButton() {
        super();
        this.addEventHandler(MouseEvent.MOUSE_CLICKED,
                        new EventHandler<MouseEvent>() {

                            @Override
                            public void handle(MouseEvent event)
                            {
                                if(!popup.isShowing()){

                                    Bounds b = me.localToScreen(me.getBoundsInLocal());
                                    double x = b.getMinX();
                                    double y = b.getMaxY();


                                    popup.setAutoHide(true);
                                    //popup.setAutoFix(true);
                                    popup.setAnchorX(x);
                                    popup.setAnchorY(y);

                                    popup.setSkin(new Skin<Skinnable>(){
                                        @Override
                                        public void dispose() {
                                        }
                                        @Override
                                        public Node getNode() {
                                            return tree;
                                        }
                                        @Override
                                        public Skinnable getSkinnable() {
                                            return null;
                                        }
                                    });;
                                    popup.show(me.getScene().getWindow());

                                }
                            }
                        });
    }
}

The tree I am working with contains CheckBoxTreeItem objects, and while the popup is working, there is some weird blur on all checkboxes, whenever the focus is not on a checkbox. (See GIF below)

CheckBoxTreeItem Blur

First, I was thinking it was maybe an antialiasing problem, but popup.getScene().getAntiAliasing().toString() returns DISABLED

Then, I saw that non integer anchor points could cause problems. However popup.setAutoFix(true) did nothing, nor did the following:

popup.setAnchorX(new Double(x).intValue());
popup.setAnchorY(new Double(y).intValue());

It might be worth noting that I am working with FXML.

How can I get sharp checkboxes regardless of their focus ?




Aucun commentaire:

Enregistrer un commentaire