Javafx change Tab X to image icon from url

2020-05-02 07:22发布

问题:

How could I change the Tabs close icon X to an image in javafx? I have tried setGraphic(), but it only takes a node... the image i want to set it to is http://eclipse-icons.i24.cc/ovr16/progress_rem.gif

回答1:

Make the image a valid node using ImageView, but that seems to be for icons.

Tab tab = new Tab();
Image image = new Image("http://eclipse-icons.i24.cc/ovr16/progress_rem.gif");
ImageView iv = new ImageView(image);
tab.setGraphic(iv);    

Get rid of the default shape in CSS or write your own or use a background image

.tab-close-button {
-fx-background-color: transparent;//-fx-mark-color;
-fx-shape:null;
-fx-background-image: url("/progress_rem.gif");
}

You'll have to provide your own click handler without the css shape, or something to click on.

This is what you get with css.



标签: java tabs javafx